如何使用python从网站实时获取一些数据?

我想从网站上获取数据

https://web.sensibull.com/optionchain?expiry=2020-03-26&tradingsymbol=NIFTY

http://img3.mukewang.com/63205019000175d613540656.jpg

我正在使用美图库来获取此数据,并尝试了以下代码:


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))

但它不起作用。


也尝试过 soup.find(“div”) 但它没有在输出中显示所需的 div 标签,可能是由于存在嵌套的 div。


无法获取此数据并继续我的工作。请帮忙。


HUX布斯
浏览 72回答 2
2回答

哈士奇WWW

如果你正在寻找代码。这可能会有所帮助:-from selenium import webdriver import timewebpage = 'https://web.sensibull.com/optionchain?expiry=2020-03-26&tradingsymbol=NIFTY'driver = webdriver.Chrome(executable_path='Your/path/to/chromedriver.exe') driver.get(webpage)time.sleep(10)nifty_fut = driver.find_element_by_xpath('//*[@id="app"]/div/div[4]/div[2]/div[3]/div/div/div[2]/div[1]/div[1]/div/button/span[1]/div[1]')print(nifty_fut.text)atm_iv = driver.find_element_by_xpath('//*[@id="app"]/div/div[4]/div[2]/div[3]/div/div/div[2]/div[1]/div[2]')print(atm_iv.text)driver.quit()

吃鸡游戏

可能是语法问题尝试或只是soup.find_all("div", class_="style__AtmIVWrapper-idZNMX kUMMRI")soup.find("div", class_="style__AtmIVWrapper-idZNMX kUMMRI")如果对网页抓取和bs4感兴趣,请查看文档 https://www.crummy.com/software/BeautifulSoup/bs4/doc/#find
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python