python获取实时股票价格_如何使用硒在网站上实时获取股票价格?

本文介绍了如何使用Python的requests和BeautifulSoup库从网站上实时获取股票价格。通过发送Ajax请求到特定URL,解析返回的HTML内容,提取出股票价格、百分比变化等关键信息。
摘要由CSDN通过智能技术生成

您可以使用requests和BeautifulSoup来获得使用Ajax查询字符串调用提到的三个项目import requests

from bs4 import BeautifulSoup

url= 'http://www.jpmhkwarrants.com/en_hk/ajax/terms_quick_search?_=1543832902362'

res = requests.get(url)

soup = BeautifulSoup(res.content, "lxml")

items = [item.text for item in soup.select('.price,.percentage.rise,li:nth-of-type(3) span')]

print(items)

结果:

24cb491a366334dcb08424665fbbdc50.png

实时框有自己的Ajax调用:

^{pr2}$

您可以使用它来检索该框中的所有项目。在import requests

from bs4 import BeautifulSoup

url= 'http://www.jpmhkwarrants.com/en_hk/ajax/market-terms-real-time-box/code/0700?_=1543832902364'

res = requests.get(url)

soup = BeautifulSoup(res.content, "lxml")

items = [item.text.strip().split('\n') for item in soup.select('.price_area div')]

tidied = [item for sublist in items for item in sublist if item and item !='Change (%)']

print(tidied)

结果:

c76bc3cd0493e0b2ba09ba030a81dc87.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值