logo
Loading...

抓取最後的table都會顯示none請問要如何解決? - Cupoy

怎麼抓取最後的table都會顯示none請問要如何解?附上程式碼from selenium impo...

pycrawler

抓取最後的table都會顯示none請問要如何解決?

2019/12/19 下午 08:48
Python網路爬蟲討論版
王得宇
觀看數:4
回答數:1
收藏數:1
pycrawler

怎麼抓取最後的table都會顯示none請問要如何解?

附上程式碼

from selenium import webdriver as sw
from selenium.webdriver.support.ui import Select
import time
driver = sw.Chrome('C:/Users/ghost/Desktop/chromedriver.exe')
driver.get("http://taqm.epa.gov.tw/taqm/tw/MonthlyAverage.aspx")
put = Select(driver.find_element_by_name('ctl05$ddlSite'))
put.select_by_value('54')
year =Select(driver.find_element_by_name('ctl05$ddlYear'))
year.select_by_value('2019')
time.sleep(10)
push = driver.find_element_by_name('ctl05$btnQuery').click()
html = driver.page_source #取得html結構
print(html)
import bs4
soup = bs4.BeautifulSoup(html , 'html.parser')
table = soup.find('table', class_='TABLE_G')
print(table)

回答列表

  • 2019/12/19 下午 11:30
    張維元 (WeiYuan)
    贊同數:0
    不贊同數:0
    留言數:0

    嗨,你的 sleep 的位置放錯,這樣才對:


    ```

    push = driver.find_element_by_name('ctl05$btnQuery').click()

    time.sleep(10)

    html = driver.page_source #取得html結構

    ```


    driver.page_source 會取得當下的瀏覽器內容,也就是說按鈕點完之後過一下之後才能擷取。