【发布时间】:2019-11-30 09:20:32
【问题描述】:
我正在寻找以下网站https://www.pro14rugby.org/match-centre/results 上的表格。
有一个小部件可以在季节之间切换。在这个小部件切换器之后,所有数据都保存在表格中。
我提取的 html 仅用于小部件切换器。
我是网络抓取的新手,因此非常欢迎指出正确的方向。
我在网络中查看是否有网址可以让我通过这一点。
def download(url, user_agent='<My_Email>', num_retries=2):
print('Downloading:', url)
headers = {'User-Agent': user_agent}
try:
resp = requests.get(url, headers=headers)
html = resp.text
if resp.status_code >= 400:
print('Download error:', resp.text)
html = None
if num_retries and 500 <= resp.status_code < 600:
# recursively retry 5xx HTTP errors
return download(url, num_retries - 1)
except requests.exceptions.RequestException as e:
print('Download error:', e)
html = None
return html
page='https://www.pro14rugby.org/match-centre/results'
html=download(page)
期待看到带有数据路径的 html 代码,正如我在检查时看到的那样。我知道这个小部件是动态的,所以我需要在代码中输入标准才能让每个赛季结束。非常欢迎对此提出任何建议。
谢谢
【问题讨论】:
-
你是说你无法获得 2018-19 赛季的第 1 轮第 2 轮等吗?或者你不能得到其他年份?
-
我什么也得不到。查看我下载的 html,我有一个 div class='bodyMain',其中我有一个 select class='widgetswitcher'(数据是每个季节)和一个 div class='widget'。当我检查页面时,我需要的数据嵌套在 div class= 'widget' 中,但在下载的 html 中没有其他内容。
标签: python html python-requests web-crawler reverse-engineering