iT邦幫忙

1

爬蟲問題 動態型網頁

我想要爬取這網頁的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()

https://ithelp.ithome.com.tw/upload/images/20200527/201238406bHmb76SCK.png
網頁網址:http://data.f139.com/trend.do?pid=15647&start=2020-05-17&end=2020-05-27

看更多先前的討論...收起先前的討論...
要登錄帳號耶.........

話說"動態"都嘛用AJAX,你只要進瀏覽器的開發者模式,在網路的項目裡找XHR,應該都能找到蛛絲馬跡
zyxa9527 iT邦新手 5 級 ‧ 2020-05-27 16:12:02 檢舉
我也是這樣想 但是空白的-.-
這種爬蟲的方式,是很講究技術。
基本上不可能找不到,只是好不好找。

其實我看了一下,我就找到幾個外連的資料。
你可以往這方面看看。我試了一下是還能抓到的。
zyxa9527 iT邦新手 5 級 ‧ 2020-05-28 16:11:13 檢舉
好哦 我在嘗試看看
還是感謝你們的幫忙
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答