我想要爬取這網頁的table,它是透過javaScript動態載入的
我使用execute_script去給日期,卻依然抓取不到動態載入的資料
有什麼其他好方式呢?
程式碼
import os
import sys
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.chrome.options import Options
import selenium.webdriver.support.ui as ui
def info_fubao():
chrome_options = Options()
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('http://www.f139.com/')
#登入 個人帳密
elem = driver.find_element_by_id("userName")
elem.send_keys(acc)
elem = driver.find_element_by_id("passWord")
elem.send_keys(pwd)
elem = driver.find_element_by_xpath('//*[@id="loginForm"]/input[6]')
elem.click()
#爬取網頁
driver.get('http://data.f139.com/trend.do?pid=15647&start=2020-05-17&end=2020-05-27')
#給日期
driver.execute_script(
"$('#begin-btn').val('2020-05-17');$('#end-btn').val('2020-05-27')"
)
#確定
elem = driver.find_element_by_xpath('//*[@id="date-btn"]')
elem.click()
#還是沒抓到
# 關閉瀏覽器視窗
driver.quit()
if __name__ == '__main__':
info_fubao()
網頁網址:http://data.f139.com/trend.do?pid=15647&start=2020-05-17&end=2020-05-27