beautiful soup selector gadget

Viewed 183

I try to get a element(number 591 in page) using selector gadget, selector gadget find "#e0 .inline:nth-child(1)" but this is not working

r = requests.get('http://www.tsetmc.com/loader.aspx?ParTree=151311&i=42031056662310763')
soup = BeautifulSoup(r.content, 'html.parser')
soup.select('#e0 .inline:nth-child(1)')

how to get this element with a selector gadget or with another way?

1 Answers

The value 591 is loaded from external URL, you can try this script to load it:

import re
import requests
from bs4 import BeautifulSoup


url = 'http://www.tsetmc.com/loader.aspx?ParTree=151311&i=42031056662310763'
html_data = requests.get(url).text
csecval = re.search(r"CSecVal='(\d+)", html_data).group(1)
i = re.search(r'i=(\d+)', url).group(1)

d = []
while not d:
    data = requests.get('http://www.tsetmc.com/tsev2/data/instinfodata.aspx', params={'i': i, 'c': csecval}).text
    d = data.split(';')[4]
print(d.split(',')[0])

Prints:

591
Related