Home > OS >  Get XHR info from URL
Get XHR info from URL

Time:10-12

I have this website https://www.futbin.com/22/player/7504 and I want to know if there is a way to get the XHR url for the information using python. For example for the URL above I know the XHR I want is https://www.futbin.com/22/playerPrices?player=231443 (got it from inspect element -> network).

My objective is to get the price value from https://www.futbin.com/22/player/1 to https://www.futbin.com/22/player/10000 at once without using inspect element one by one.

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'])

CodePudding user response:

You can find the player-resource id and build the url yourself. I use beautifulsoup. It's made for parsing websites, but you can take the requests content and throw that into an html parser as well if you don't want to install beautifulsoup

With it, read the first url, get the id and use your code to pull the prices. To test, change the 10000 to 2 or 3 and you'll see it works.

import re 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'])
  • Related