我正在尝试通过解析html编译以下代码,但出现错误:

import string, urllib2, urlparse, csv, sys
from urllib import quote
from urlparse import urljoin
from bs4 import BeautifulSoup
from ast import literal_eval

changable_url = 'http://www.asusparts.eu/partfinder/Asus/All%20In%20One/E%20Series'
page = urllib2.urlopen(changable_url)
base_url = 'http://www.asusparts.eu'
soup = BeautifulSoup(page)

selects = []
redirects = []
model_info = []

#Opening csv writer
c = csv.writer(open(r"asus_stock.csv", "wb"))
#Object reader
cr = csv.reader(open(r"asus_stock.csv", "rb"))

print "FETCHING OPTIONS"
select = soup.find(id='myselectListModel')
selects.append(select)
print selects.get_text()


错误是:

print selects.get_text()
AttributeError: 'list' object has no attribute 'get_text'


我如何传递此错误?谢谢。

最佳答案

您正在列表中的get_text()上运行selects函数。列表没有该功能。

您不应该在select本身上运行它吗?或选择的每个元素呢?

for item in selects:
   print item.get_text()

关于python - Python'get_text()'不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16167348/

10-12 22:48