【发布时间】:2018-07-14 20:15:22
【问题描述】:
我正在努力从这个网站上抓取表格:
具体来说,我正在尝试为表中列出的每个游戏的“Westgate”行刮取“Run Line”列。
我不确定自己做错了什么,因为我只是想深入了解表格中的文本,根据我对网络抓取的有限理解,这将是我选择的“奇怪”表格中的第二个表格。
我已尝试搜索我的问题,但在将任何建议的解决方案应用于我的特定场景时遇到了麻烦。
提前感谢您的帮助。
这是我目前的代码
url='http://www.espn.com/mlb/lines'
driver = webdriver.Chrome()
driver.get(url)
time.sleep(5)
content=driver.page_source
soup=BeautifulSoup(content,'lxml')
driver.quit()
table=soup.find('table',{'class':'tablehead'})
table_row=table.find_all('tr',{'class':'oddrow'})
table_data=table_row.find_all('table',{'class':'tablehead'})[1] #trying to
#just scrape the second table only within this row, ie the Westgate and Runline table
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-397-fea09cb40cb2> in <module>()
----> 1 table_data=table_row.find_all('table',{'class':'tablehead'})
~\Anaconda3\lib\site-packages\bs4\element.py in __getattr__(self, key)
1805 def __getattr__(self, key):
1806 raise AttributeError(
-> 1807 "ResultSet object has no attribute '%s'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?" % key
1808 )
AttributeError: ResultSet object has no attribute 'find_all'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?
【问题讨论】:
标签: python python-3.x beautifulsoup