我想从网站获取som数据
https://web.sensibull.com/optionchain?expiry=2020-03-26&tradingsymbol=NIFTY
我正在使用beautifulsoup库获取此数据,并尝试了以下代码:
import requests
import urllib.request
import time
from bs4 import BeautifulSoup
url = 'https://web.sensibull.com/optionchain?expiry=2020-03-26&tradingsymbol=NIFTY'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
b = soup.find("div", {"class": "style__AtmIVWrapper-idZNMX kUMMRI"})
print(b)
但它显示“无”作为输出
虽然在完整的HTML代码中只有一个同名类,但我也尝试了以下方法:
for b in soup.find_all('div', attrs={'class':'style__AtmIVWrapper-idZNMX kUMMRI'}):
print(b.get_text())
print(len(b))
但它不起作用
还尝试了汤。查找(“div”) 但它没有在输出中显示所需的div标记,可能是因为存在嵌套的div
无法获取此数据并继续我的工作。请帮忙
可能是语法问题,请尝试使用
soup.find_all("div", class_="style__AtmIVWrapper-idZNMX kUMMRI")
或仅使用soup.find("div", class_="style__AtmIVWrapper-idZNMX kUMMRI")
如果对webscraping和bs4感兴趣,请查看文档https://www.crummy.com/software/BeautifulSoup/bs4/doc/#find
如果您正在寻找代码。这可能有助于:
相关问题 更多 >
编程相关推荐