[英]beautiful soup selector gadget
我嘗試使用選擇器小工具獲取元素(頁面中的編號 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)')
如何使用選擇器小工具或其他方式獲取此元素?
值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])
印刷:
591
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.