Jensen Benny
Jensen Benny

Reputation: 25

Parsing info revealed on button click

I'm trying to parse this page: https://www.website.com/details/

There is a phone number button hiding the part of the phone number. On click, ajax post request brings in the complete phone number.

How can I fake this post request in python?

import requests, time, json from bs4 import BeautifulSoup

headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36", } s = requests.Session()

response = s.get( "https://www.mashina.kg/details/kia-sorento-64631fe26592a662606296", headers=headers )

soup = BeautifulSoup(response.text, "lxml")

Upvotes: 1

Views: 77

Answers (1)

Andrej Kesely
Andrej Kesely

Reputation: 195438

Try:

import requests
from bs4 import BeautifulSoup

url = 'https://www.mashina.kg/details/kia-sorento-64631fe26592a662606296'

headers  = {
    'X-Requested-With': 'XMLHttpRequest'
}

soup = BeautifulSoup(requests.get(url + '/givemereal', headers=headers).content, 'html.parser')
for n in soup.select('.number'):
    print(n.text)

This will print the telephone numbers.

Upvotes: 2

Related Questions