我正在尝试从 this 中抓取之前的收盘价和开盘价网站。这是一张图像,作为要抓取的信息所在位置的引用。
看起来特定的表是带有 class="col-lg-13"
的 div
标记的子级,但 bs4 仅返回 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
我也尝试过:
container = soup.find('div', attr={'ng-init': "fnStockTrading()"})
tables = container.find_all('table')
print(tables)
>>> []
最佳答案
使用页面用于数据的相同 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)
关于python - 无法使用 bs4 从 BSE 网站上抓取特定信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56036758/