【发布时间】:2016-09-19 02:08:23
【问题描述】:
我正在尝试从谷歌金融获取一些信息,但我收到了这个错误
AttributeError: 'HTTPResponse' 对象没有属性 'split'
这是我的python代码:
import urllib.request
import urllib
from bs4 import BeautifulSoup
symbolsfile = open("Stocklist.txt")
symbolslist = symbolsfile.read()
thesymbolslist = symbolslist.split("\n")
i=0
while i<len (thesymbolslist):
theurl = "http://www.google.com/finance/getprices?q=" + thesymbolslist[i] + "&i=10&p=25m&f=c"
thepage = urllib.request.urlopen (theurl)
print(thesymbolslist[i] + " price is " + thepage.split()[len(thepage.split())-1])
i= i+1
【问题讨论】:
-
你想在这里做什么?
thepage.split()[len(thepage.split())-1]) -
我正在尝试将页面放入列表中,然后从该列表中获取最后一个属性并打印它。
-
您需要从
thepage到read()才能得到一个实际的字符串。
标签: python python-3.x