这是我目前拥有的代码:
from bs4 import BeautifulSoup
import requests
url = requests.get("http://eiupanthers.com/boxscore.aspx?path=baseball&id=5065").content
soup = BeautifulSoup(url, 'html.parser')
table = soup.find('table', {'class': 'sidearm-table play-by-play'})
我的表变量不断返回为空(或“无”)。这可能仅仅是语法问题。我非常精通Matlab,但是,我对Python / BeautifulSoup / Requests / etc很陌生。
任何指针将不胜感激。
我主要是尝试从逐个播放表中提取数据,以便可以在备用程序中解析此数据并为单个播放器组装数据结构。我有信心在组装数据后就可以完成这一部分。
谢谢你的帮助!
from bs4 import BeautifulSoup
import requests
header = {'User-agent' : 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5'}
url = requests.get("http://eiupanthers.com/boxscore.aspx?path=baseball&id=5065", headers=header).text
soup = BeautifulSoup(url, 'html.parser')
table = soup.find('table', {'class': 'sidearm-table play-by-play'})
print(table)
问题似乎是该网站需要某种标题,即使该request
模块具有相当好的支持,您也必须传递例如上述内容。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句