String Python 2.7:未知url类型:urllib2-BeautifulSoup 导入库 新图书馆:
定义变量:String Python 2.7:未知url类型:urllib2-BeautifulSoup 导入库 新图书馆:,string,python-2.7,url,beautifulsoup,urllib2,String,Python 2.7,Url,Beautifulsoup,Urllib2,定义变量: i = 1 str_i = str(i) seqPrefix = 'seq_' seq_1 = str('https://anyaddress.com/') quote_page = seqPrefix + str_i #然后,使用Python urllib2获取声明的url的HTML页面 # query the website and return the html to the variable 'page' page = urllib2.urlopen(quote_page)
i = 1
str_i = str(i)
seqPrefix = 'seq_'
seq_1 = str('https://anyaddress.com/')
quote_page = seqPrefix + str_i
#然后,使用Python urllib2获取声明的url的HTML页面
# query the website and return the html to the variable 'page'
page = urllib2.urlopen(quote_page)
#Finally, parse the page into BeautifulSoup format so we can use BeautifulSoup to work on it.
# parse the html using beautiful soup and store in variable `soup`
soup = BeautifulSoup(page, 'html.parser')
因此,一切都很好……除了:
错误消息:
page=urlib2.urlopen(引用页面)
文件“C:\Python27\lib\urllib2.py”,第154行,在urlopen中
返回opener.open(url、数据、超时)
文件“C:\Python27\lib\urllib2.py”,第423行,打开
协议=请求获取类型()
文件“C:\Python27\lib\urllib2.py”,第285行,get\u类型
提升值错误,“未知url类型:%s”%self.\u原始
ValueError:未知url类型:seq_1
为什么?
txs.您可以使用局部变量字典vars()
按照您的方式,它试图使用字符串“seq_1”作为URL而不是有效URL的seq_1变量的值来打开URL。您可以使用局部变量字典vars()
按照您的方式,它试图使用字符串“seq_1”作为URL而不是有效URL的seq_1变量的值来打开URL。看起来您需要concat
seq_1
&str_i
Ex:
seq_1 = str('https://anyaddress.com/')
quote_page = seq_1 + str_i
https://anyaddress.com/1
输出:
seq_1 = str('https://anyaddress.com/')
quote_page = seq_1 + str_i
https://anyaddress.com/1
看起来您需要连接
seq_1
&str_i
Ex:
seq_1 = str('https://anyaddress.com/')
quote_page = seq_1 + str_i
https://anyaddress.com/1
输出:
seq_1 = str('https://anyaddress.com/')
quote_page = seq_1 + str_i
https://anyaddress.com/1