抓取动态页面时使用 request-html 指定时间范围
specify time range using request-html when scraping a dynamic page
我最近正在为一个朋友抓取足球赛果,这让我着迷。下面是 link:
https://www.mlssoccer.com/mlsnext/schedule/2021-2022/u16_mls-next-schedule
我正在尝试从 selenium
切换到 request-html
。我首先使用 selenium
的原因是这是我知道的唯一选择 单击日历。
默认日期是当前日期,但我需要所有比赛历史记录,是否可以使用 request-html
更改默认日期,如果可以,如何?
提前感谢您的时间和精力,我们将不胜感激任何有用的建议。
---------------------------- 编辑------ ----------------------
经过一段时间的搜索,我发现以下可能的方法可以使用 request-html
,
url= "https://www.modular11.com/public_schedule/league/get_matches"
session = HTMLSession()
response = session.post(url, data={"start_date": "2021-10-30 00:00:00"})
print(response.url)
# print(response.text)
response.html.render(timeout=1200)
print(response.html.text)
Please select the gender, league & age of the matches you are looking for.
$(function () { // Fix event duplicate $('.main_row').unbind('click'); $('.main_row').on('click', function () { $(this) .find('button.icon') .children('span') .toggleClass('glyphicon glyphicon-menu-down') .toggleClass('glyphicon glyphicon-menu-up'); if ($(this).find('button.icon span').hasClass('glyphicon-menu-down')) { $(this) .closest('.container-row') .find('.table-row-heading') .addClass('hidden-mobile'); $(this) .closest('.container-row') .find('.table-content-row') .addClass('hidden-xs hidden-sm'); $(this).css({ 'background-color': 'inherit', 'color': '#0B0B33' }); $(this) .closest('.container-row') .find('.mobile-scrolling') .removeClass('hide-scrolling'); } else if ($(this).find('button.icon span').hasClass('glyphicon-menu-up')) { $(this) .closest('.container-row') .find('.table-row-heading') .removeClass('hidden-mobile'); $(this) .closest('.container-row') .find('.table-content-row') .removeClass('hidden-xs hidden-sm'); $(this).css({ 'background-color': '#2A3851', 'color': '#EEEEEE !important' }); $(this) .closest('.container-row') .find('.mobile-scrolling') .addClass('hide-scrolling'); } }); });
但似乎data
部分没有正确发送到服务器,因此返回:
日历发出 xhr 请求(您可以使用浏览器网络工具的网络选项卡进行监控),并带有易于自定义的查询字典。请求 returns html 您必须用漂亮的汤解析的数据
import requests
query_dict={'open_page': ['0'], 'academy': ['0'], 'league': ['12'], 'gender': ['1'], 'age': ['["14"]'], 'brackets': ['null'], 'groups': ['null'], 'group': ['null'], 'match_number': ['0'], 'status': ['scheduled'], 'match_type': ['2'], 'schedule': ['0'], 'start_date': ['2021-11-03 00:00:00'], 'end_date': ['2021-11-10 23:59:00']}
r = requests.post('https://www.modular11.com/public_schedule/league/get_matches', data = query_dict)
print(r.text)
我最近正在为一个朋友抓取足球赛果,这让我着迷。下面是 link:
https://www.mlssoccer.com/mlsnext/schedule/2021-2022/u16_mls-next-schedule
我正在尝试从 selenium
切换到 request-html
。我首先使用 selenium
的原因是这是我知道的唯一选择 单击日历。
默认日期是当前日期,但我需要所有比赛历史记录,是否可以使用 request-html
更改默认日期,如果可以,如何?
提前感谢您的时间和精力,我们将不胜感激任何有用的建议。
---------------------------- 编辑------ ----------------------
经过一段时间的搜索,我发现以下可能的方法可以使用 request-html
,
url= "https://www.modular11.com/public_schedule/league/get_matches"
session = HTMLSession()
response = session.post(url, data={"start_date": "2021-10-30 00:00:00"})
print(response.url)
# print(response.text)
response.html.render(timeout=1200)
print(response.html.text)
Please select the gender, league & age of the matches you are looking for.
$(function () { // Fix event duplicate $('.main_row').unbind('click'); $('.main_row').on('click', function () { $(this) .find('button.icon') .children('span') .toggleClass('glyphicon glyphicon-menu-down') .toggleClass('glyphicon glyphicon-menu-up'); if ($(this).find('button.icon span').hasClass('glyphicon-menu-down')) { $(this) .closest('.container-row') .find('.table-row-heading') .addClass('hidden-mobile'); $(this) .closest('.container-row') .find('.table-content-row') .addClass('hidden-xs hidden-sm'); $(this).css({ 'background-color': 'inherit', 'color': '#0B0B33' }); $(this) .closest('.container-row') .find('.mobile-scrolling') .removeClass('hide-scrolling'); } else if ($(this).find('button.icon span').hasClass('glyphicon-menu-up')) { $(this) .closest('.container-row') .find('.table-row-heading') .removeClass('hidden-mobile'); $(this) .closest('.container-row') .find('.table-content-row') .removeClass('hidden-xs hidden-sm'); $(this).css({ 'background-color': '#2A3851', 'color': '#EEEEEE !important' }); $(this) .closest('.container-row') .find('.mobile-scrolling') .addClass('hide-scrolling'); } }); });
但似乎data
部分没有正确发送到服务器,因此返回:
日历发出 xhr 请求(您可以使用浏览器网络工具的网络选项卡进行监控),并带有易于自定义的查询字典。请求 returns html 您必须用漂亮的汤解析的数据
import requests
query_dict={'open_page': ['0'], 'academy': ['0'], 'league': ['12'], 'gender': ['1'], 'age': ['["14"]'], 'brackets': ['null'], 'groups': ['null'], 'group': ['null'], 'match_number': ['0'], 'status': ['scheduled'], 'match_type': ['2'], 'schedule': ['0'], 'start_date': ['2021-11-03 00:00:00'], 'end_date': ['2021-11-10 23:59:00']}
r = requests.post('https://www.modular11.com/public_schedule/league/get_matches', data = query_dict)
print(r.text)