在页面上拖动后清空html标记

2024-09-27 04:27:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在努力清理网站:

http://finance.sina.com.cn/futures/quotes/I0.shtml?from=wap

捕捉中国铁矿石的变化:

enter image description here

刮完之后,我搜索标签,发现所有东西都是空的

我正在使用:

url2 = 'http://finance.sina.com.cn/futures/quotes/I0.shtml?from=wap'
html2 = urlopen(url2)
bs2 = BeautifulSoup(html2, 'lxml')
print(bs2.title)

print(bs2.find_all('span', class_ = 'amt'))

输出:

<title>铁矿石2005(I0)期货行情,新闻,报价_新浪财经_新浪网</title>
[<span class="amt">--</span>, <span class="amt">--</span>, <span class="amt">--</span>, <span class="amt">--</span>, <span class="amt">--</span>, <span class="amt">--</span>, <span class="amt">--</span>, <span class="amt">--</span>, <span class="amt">--</span>, <span class="amt">--</span>, <span class="amt">--</span>, <span class="amt">--</span>, <span class="amt">--</span>, <span class="amt">--</span>, <span class="amt">--</span>, <span class="amt">--</span>,.....

我已经打开浏览器控制台,查看该站点正在调用的其他页面,并发现以下两个页面:

http://hq.sinajs.cn/?_=1584562106303/&list=sz002578,sz002082,sz002167,sz002501,sh600432,sh600255,sz002160,sz002379,sz002428,sh600311,nf_RB2005,nf_I2005,nf_P2005,nf_M2009,nf_Y2005,nf_JD2005,nf_FU2005,nf_BU2006,hf_CAD,hf_CL,hf_GC,hf_SI,hf_S,hf_BO,hf_C,hf_W,hf_AHD,hf_OIL,nf_I0,nf_I2005

http://hq.sinajs.cn/?_=1584562106303/&list=nf_I0

但没有发现资产的变化。。。。。(+0.16%)

你能帮我解决这个问题吗


Tags: comhttptitlecnclassquotesspanfinance
2条回答

我认为这是因为0.16%在网页首次加载时并不存在

它是由javascript动态生成的,据我所知BeautifulSoup无法处理这种情况

你可以在这个link中找到与这个问题类似的答案

我建议使用硒。虽然速度较慢,但会起作用 见https://www.selenium.dev/

相关问题 更多 >

    热门问题