Html 我错过了哪些头球来获取NBA统计数据?

Html 我错过了哪些头球来获取NBA统计数据?,html,json,web-scraping,powerbi,host,Html,Json,Web Scraping,Powerbi,Host,几天前,在PowerBI中,我能够创建一个web查询,允许我从中提取JSON数据,而无需使用任何标题。到今天为止,我注意到这个查询已经不起作用了;我收到以下错误消息: DataSource.Error: The underlying connection was closed. An unexpected error occurred on a receive. Details: https://stats.nba.com/stats/leaguedashplayerstats?College=

几天前,在PowerBI中,我能够创建一个web查询,允许我从中提取JSON数据,而无需使用任何标题。到今天为止,我注意到这个查询已经不起作用了;我收到以下错误消息:

DataSource.Error: The underlying connection was closed. An unexpected error occurred on a receive.
Details: https://stats.nba.com/stats/leaguedashplayerstats?College=&Conference=&Country=&DateFrom=&DateTo=&Division=&DraftPick=&DraftYear=&GameScope=&GameSegment=&Height=&LastNGames=0&LeagueID=00&Location=&MeasureType=Base&Month=0&OpponentTeamID=0&Outcome=&PORound=0&PaceAdjust=N&PerMode=PerGame&Period=0&PlayerExperience=&PlayerPosition=&PlusMinus=N&Rank=N&Season=2019-20&SeasonSegment=&SeasonType=Regular+Season&ShotClockRange=&StarterBench=&TeamID=0&TwoWay=0&VsConference=&VsDivision=&Weight=
Unable to connect

We encountered an error while trying to connect.

Details: "The 'Host' header must be modified using the appropriate property or method.
Parameter name: name"
与此相关的是,我曾经能够使用
https://stats.nba.com/
作为
Referer
标题,但现在它给我的错误消息与上面显示的相同。为了避免这些错误,我尝试输入以下标题:

Host: stats.nba.com
Connection: keep-alive
Accept: application/json
x-nba-stats-token: true
User-Agent: Chrome/79.0.3945.130
x-nba-stats-origin: stats
Referer: https://stats.nba.com/
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
当我提交带有上述标题的查询时,返回的错误消息如下:

DataSource.Error: The underlying connection was closed. An unexpected error occurred on a receive.
Details: https://stats.nba.com/stats/leaguedashplayerstats?College=&Conference=&Country=&DateFrom=&DateTo=&Division=&DraftPick=&DraftYear=&GameScope=&GameSegment=&Height=&LastNGames=0&LeagueID=00&Location=&MeasureType=Base&Month=0&OpponentTeamID=0&Outcome=&PORound=0&PaceAdjust=N&PerMode=PerGame&Period=0&PlayerExperience=&PlayerPosition=&PlusMinus=N&Rank=N&Season=2019-20&SeasonSegment=&SeasonType=Regular+Season&ShotClockRange=&StarterBench=&TeamID=0&TwoWay=0&VsConference=&VsDivision=&Weight=
Unable to connect

We encountered an error while trying to connect.

Details: "The 'Host' header must be modified using the appropriate property or method.
Parameter name: name"

关于如何正确运行查询,我已经没有什么想法了。我对网页抓取和HTML非常陌生——我一直在努力自学。非常感谢您的帮助。

GET请求的所有标题:

Host: stats.nba.com
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: application/json, text/plain, */*
x-nba-stats-token: true
X-NewRelic-ID: VQECWF5UChAHUlNTBwgBVw==
DNT: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
x-nba-stats-origin: stats
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Referer: https://stats.nba.com/teams/traditional/?sort=TEAM_NAME&dir=-1
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US;q=0.9,en;q=0.7
网址:

所需标题:

Accept: application/json, text/plain, */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
x-nba-stats-origin: stats
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Referer: https://stats.nba.com/teams/traditional/?sort=TEAM_NAME&dir=-1
不确定是否需要:

x-nba-stats-token: true
X-NewRelic-ID: VQECWF5UChAHUlNTBwgBVw==
可能的问题

  • 您检测到一个机器人并被阻止

  • 标头
    X-NewRelic-ID
    是一个令牌(可能带有超时)。它可能是使用不同的参数分配的,比如
    IP
    、用户代理等
    您可以在HTML响应中使用get request to
    获取新鲜的
    X-NewRelic-ID
    https://stats.nba.com/
    。 以下是HTML中带有
    xpid
    标记的部分:
    (window.NREUM | |(NREUM={})).loader_config={xpid:“VQECWF5UChAHUlNTBwgBVw==”,licenseKey:“09f0cb5c68”,applicationID:“76210961”}


  • 输入所有这些标题后,它会给我与我在问题中关于“主机”标题相同的“无法连接”错误消息。请检查答案更新。我认为你被检测为机器人并被阻止。从不同的IP尝试。你可以使用代理。你能在你的终端提取JSON数据吗?我很想知道你是否能够这样做,这样我就可以确定这是否是我这边的事情——比如我被检测为机器人。是的,我能够提取。你是否使用了所有需要的标题?我已经试过做所需的,以及
    x-nba-stats-token:true
    x-NewRelic-ID:VQECWF5UChAHUlNTBwgBVw==
    ,但仍然无法拉取。请将错误消息添加为文本,而不是屏幕截图。请注意,您可能违反了网站的服务条款。你踩在了不稳固的法律基础上…更新了。谢谢你的提醒。