python - Beautifulsoup 按其类名提取 div
问题描述
我正在尝试从 html 页面中提取表格,
以下是我尝试过的代码,
driver = webdriver.Chrome(executable_path='C:/Users/krish/Desktop/Python/chromedriver.exe')
driver.get('https://www.marketsmojo.com/Stocks?StockId=592009&Exchange=0#navQuality')
driver.implicitly_wait(50)
soup = BeautifulSoup(driver.find_element_by_id("table1 comp2-table ng-tns-c94-1"),'lxml')
tables = soup.find_all("div", {"class": "card ng-tns-c94-1"})
hdfc_mm = pd.read_html(str(tables))
我正在尝试从提到的网站的质量菜单栏中提取一个表格。之后我通过在表格上使用检查来命名,并找到带有 divsion 类的表格名称。
但我收到以下错误,
无法定位元素:{"method":"css selector","selector":"[id="table1 comp2-table ng-tns-c94-1"]"}
突出显示所需的表。
如何找到表?请有任何想法。
谢谢
解决方案
这来自一个 API:
GET https://frapi.marketsmojo.com/stocks_quality/cardinfo?std={id}
它需要来自 url 查询参数的 id:
import requests
sid = "592009"
r = requests.get(f"https://frapi.marketsmojo.com/stocks_quality/cardinfo?sid={sid}")
print(r.json()["data"]["quality_tbl"]["list"])
推荐阅读
- tensorflow - 为什么 ```on_epoch_end()``` 从 google cloud ml 引擎上的几个工作人员调用?
- java - 使用数组变量的 Nullpointerexception
- python - 可以从shogun的python界面控制随机种子吗?
- javascript - Phonegap 应用程序首次启动后无法访问 ajax
- node.js - 如何解决nodejs中的循环依赖错误?
- c# - Net Core:从集成测试中查找应用程序组装位置
- python - 如何使用python转换excel数据
- solr - 如何索引这种情况?
- java - 您如何在现有活动之上进行透明活动(我已经研究无济于事)
- css - 如何在不导致页面滚动的情况下使元素成为最大高度?