我尝试使用选择器小工具获取一个元素(页面中的591个),选择器小工具查找“#e0.inline:nth-child(1)”,但这不起作用
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)')如何使用选择器小工具或其他方式获取此元素?
发布于 2020-07-27 02:06:22
值591是从外部URL加载的,您可以尝试此脚本来加载它:
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])打印:
591https://stackoverflow.com/questions/63103512
复制相似问题