[英]web scraping problem with data i don't know how to export information from file.html to my python programme
[英]Web scraping using Python and Selenium, don't know how to get dynamic data
我正在嘗試從表中獲取值,但它們不在HTML中。 然而, 他們在HTML,當我在瀏覽器對其進行檢查。 我猜它們是動態生成的,但是如何在Selenium或Python中捕獲它們呢?
你可以這樣
from selenium import webdriver
import pandas as pd
import time
driver = webdriver.Chrome()
driver.get('https://www.predictit.org/Contract/7422/Will-Trump-veto-Russian-sanctions-bill-by-August-31#prices')
time.sleep(2)
tables = pd.read_html(driver.page_source) # returns list of dataframes
print(len(tables))
print(tables[2]) # this is table with YES
print(tables[3]) # this is the table with NO
該代碼僅獲取表,但是您需要進行一些清理。 您可以閱讀pandas.DataFrame
的文檔
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.