Home > Blockchain >  How do I fetch all the price from this url using Beautiful soup?
How do I fetch all the price from this url using Beautiful soup?

Time:10-01

I tried all the methods but unable to fetch the price from this particular website. I am getting None as the output.

import bs4
import requests
u = 'https://skinport.com/market?cat=Knife&item=Doppler&type=M9 Bayonet&sort=price&order=asc'
r = requests.get(u)
c = r.content
soup = bs4.BeautifulSoup(c, "html.parser")
price = soup.findall("div", {"class": "Tooltip-link"})
print(price)

CodePudding user response:

There are no elements like that, as they don't exist in the HTML when you first download the page. They are downloaded asynchronously via this API request. Instead, you could directly download the JSON data from the API request and parse it using JSON, like so:

from json import loads
from requests import get

data = loads(
    get("https://skinport.com/api/browse/730?cat=Knife&item=Doppler&type=M9 Bayonet&sort=price&order=asc").text
)

CodePudding user response:

This prints the divs you want. Note that the API is find_all, not findall.

c = r.content.decode('utf-8')
soup = bs4.BeautifulSoup(c, "html.parser")
price = soup.find_all( 'div', {"class": "Tooltip-link"})
print(price)
  • Related