【发布时间】:2018-11-20 01:06:01
【问题描述】:
导入库
import urllib2
from bs4 import BeautifulSoup
新库:
import csv
import requests
import string
定义变量:
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 = urllib2.urlopen(quote_page) 文件“C:\Python27\lib\urllib2.py”,第 154 行,在 urlopen 返回 opener.open(url, 数据, 超时) 文件“C:\Python27\lib\urllib2.py”,第 423 行,打开 协议 = req.get_type() 文件“C:\Python27\lib\urllib2.py”,第 285 行,在 get_type 引发 ValueError,“未知 url 类型:%s”% self.__original ValueError:未知的 url 类型:seq_1
为什么?
发送。
【问题讨论】:
标签: string python-2.7 url beautifulsoup urllib2