如何把东方财富网上一只股票实时价格爬下来
from requests_html import HTMLSession#需求,把东方财富网上,一只股票的实时报价给爬下来
url='http://quote.eastmoney.com/sz300142.html'
session=HTMLSession()
head={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36'}
ret=session.get(url,headers=head)
res=ret.html #<HTML url='http://quote.eastmoney.com/sz300142.html'>
res.render()
prcie=res.html.find('#price9')
print(prcie)
**************************************************************
结果显示为-1,可目前价格明明是56.83,有点不知所措。。。 本帖最后由 isdkz 于 2022-3-23 12:46 编辑
HTML 对象的 html 属性返回的是一个字符串,字符串的 find 方法找不到指定字符串会返回 -1,
故对你的代码修改如下
from requests_html import HTMLSession
#需求,把东方财富网上,一只股票的实时报价给爬下来
url='http://quote.eastmoney.com/sz300142.html'
session=HTMLSession()
head={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36'}
ret=session.get(url,headers=head)
res=ret.html #<HTML url='http://quote.eastmoney.com/sz300142.html'>
res.render()
prcie=res.find('#price9').text # 修改这里
print(prcie) isdkz 发表于 2022-3-23 12:40
HTML 对象的 html 属性返回的是一个字符串,字符串的 find 方法找不到指定字符串会返回 -1,
故对你的代 ...
厉害{:5_106:},HTML 对象的 html 属性这些信息应该去那里看呀,我找了一下菜鸟教程上也没有
页:
[1]