通過的同一品種大約有十幾個問題,巡航,並諮詢了同事後,我決定,我需要一些專家的見解AttributeError的:「功能」對象有沒有屬性「find_all」美麗的湯
with open("c:\source\list.csv") as f:
for row in csv.reader(f):
for url in row:
r = requests.get(url)
soup = BeautifulSoup(r.content, 'lxml')
tables = soup.find('table', attrs={"class": "hpui-standardHrGrid-table"}).append
for rows in table.find_all('tr', {'releasetype': 'Current_Releases'}):
item = [].append
for val in row.find_all('td'):
item.append(val.text.encode('utf8').strip())
rows.append(item)
headers = [header.text for header in tables.find_all('th')].append
rows = [].append
print (headers)
所以我在這裏是:一個csv文件,其中有30個URL。我首先將它們轉儲到Soup中以獲取它的所有內容,然後將特定的HTML元素(表)綁定到tables變量。在此之後,我試圖從這些表中拉出特定的行和標題。
根據我的大腦的邏輯思維,它應該工作,而是我得到這個:
Traceback (most recent call last):
File "<stdin>", line 7, in <module>
AttributeError: 'function' object has no attribute 'find_all'
7號線是
for rows in table.find_all('tr', {'releasetype': 'Current_Releases'}):
什麼是我們在這裏失蹤?
爲什麼你在'tables = soup.find('table',attrs = {「class」:「hpui-standardHrGrid-table」})末尾加上'.append'? – roganjosh
什麼是「表」?我猜錯了嗎?另外,'[] .append'應該是什麼意思?在嘗試編寫任何代碼之前,請學習一些Python。 – ForceBru
你不可能是一個***洞嗎?我正在學習。無可否認,我是一個絕對的新手,他的任務是創建這個程序。我使用append將30個表追加到一個變量中。 –