从URL获取XHR信息



我有这个网站https://www.futbin.com/22/player/7504,我想知道是否有办法获得使用python的信息的XHR url。例如,对于上面的URL,我知道我想要的XHR是https://www.futbin.com/22/playerPrices?player=231443(从inspect element ->网络).

我的目标是立即获得从https://www.futbin.com/22/player/1到https://www.futbin.com/22/player/10000的价格值,而不需要逐个使用inspect元素。

import requests
URL = 'https://www.futbin.com/22/playerPrices?player=231443'
page = requests.get(URL)
x = page.json()
data = x['231443']['prices']
print(data['pc']['LCPrice'])
print(data['ps']['LCPrice'])
print(data['xbox']['LCPrice'])

您可以找到播放器资源id并自己构建url。我用的是美味的汤。它是为解析网站而设计的,但如果你不想安装beautifulsoup

,你也可以把请求的内容扔到html解析器中。有了它,读取第一个url,获取id并使用代码拉出价格。要进行测试,将10000更改为2或3,您将看到它的工作原理。

import re, requests
from bs4 import BeautifulSoup
for i in range(1,10000):
url = 'https://www.futbin.com/22/player/{}'.format(str(i))
html = requests.get(url).content
soup = BeautifulSoup(html, "html.parser")
player_resource = soup.find(id=re.compile('page-info')).get('data-player-resource')
# print(player_resource)
URL = 'https://www.futbin.com/22/playerPrices?player={}'.format(player_resource)
page = requests.get(URL)
x = page.json()
# print(x)
data = x[player_resource]['prices']
print(data['pc']['LCPrice'])
print(data['ps']['LCPrice'])
print(data['xbox']['LCPrice'])

最新更新