无法使用bs4从BSE网站上抓取特定信息

时间:2019-05-08 08:41:39

标签: python web-scraping beautifulsoup

我正试图从this网站上抓取先前的收盘价和开盘价。这是一张图片,作为要抓取的信息所在位置的参考。

stock info table

看起来特定的表是带有div的{​​{1}}标记的子表,但是bs4在所有尝试找到它的过程中仅返回class="col-lg-13"

我尝试了以下操作:

None

我也尝试过:

from bs4 import BeautifulSoup
import requests

link = "https://bseindia.com/stock-share-price/bharat-gears-ltd/bharatgear/505688/"
resp = requests.get(link).content
soup = BeautifulSoup(resp, "lxml")

box = soup.find('div', class_="col-lg-13")
table = box.find('table')
print(table)

>>> None

1 个答案:

答案 0 :(得分:2)

使用页面用于数据的相同URL(API)。可以在“网络”标签中找到

import requests
r = requests.get('https://api.bseindia.com/BseIndiaAPI/api/getScripHeaderData/w?Debtflag=&scripcode=505688&seriesid=').json()
prev_close = r['Header']['PrevClose']
prev_open = r['Header']['Open']
print(prev_close, prev_open)
相关问题