2
好吧,我想用美麗的湯來提取一些信息的開瓶器,我認爲這就是問題出現的地方。我需要使用opener,因爲我需要通過Tor路由它,因爲我認爲它們阻止了多個請求。AttributeError:addinfourl實例沒有屬性'get_type'
(如果這是所有未格式化我將修改直線距離,因爲通常是一些奇怪的情況發生)
下面的代碼:
def getsite():
proxy = urllib2.ProxyHandler({"http" : "127.0.0.1:8118"})
opener = urllib2.build_opener(proxy)
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
url = opener.open('https://www.website.com')
try:
page = BeautifulSoup(urllib2.urlopen(url).read())
except Exception as Err:
errorlist.append('Unexpected Error ' + str(Err))
time.sleep(60)
page = BeautifulSoup(urllib2.urlopen(url).read())
values = page.findAll("strong")
high = values[2]
low = values[1]
last = values[0]
vol = values[3]
high = str(high)
low = str(low)
last = str(last)
vol = str(vol)
high = high[8:-13]
low = low[8:-13]
last = last[8:-13]
vol = vol[8:-24]
print high, low, last, vol
while True:
getsite()
time.sleep(3200)
它拋出了這個錯誤。
page = BeautifulSoup(urllib2.urlopen(url).read()) File "C:\Python27\lib\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py", line 392, in open
protocol = req.get_type() AttributeError: addinfourl instance has no attribute 'get_type'
呃,我不太清楚這一點。它的工作原理,但不再使用opener了嗎? 你能解釋一下嗎? 編輯:沒關係,弄糊塗了。謝了哥們。 – tommo 2013-02-15 02:27:27