標題: 新手用python 爬蟲 希望各路高手教路 [打印本頁]
作者: tonyhehahk 時間: 2018-8-22 21:29 標題: 新手用python 爬蟲 希望各路高手教路
最近我自學用python
嘗試用python 爬蟲
目標是以下這個足球網站
http://www.hkjcodds.com/
我知道個JS唔可以就咁爬 就用selinium
不過selinium 都找不到相關的數據
即使佢係彈多左堆野 過左個API 但有D資料都出唔曬
但js/json 後面果堆數據我都搵唔倒 XMR 又得一個FILE JS就一大堆
我就咁用網頁開發者模式都唔知堆數據放係邊 (咩初/終果D同堆數字果D)
點解會咁樣 爬極都爬唔倒想要堆數 又唔知要request 邊度好
果堆code如下
-----------------------------------------------------------------------
from selenium import webdriver
import requests as rq
import time
import pandas as pd
driver = webdriver.Chrome()
driver.get('http://www.hkjcodds.com/')
def tryclick(driver, selector, count=0): ##保護機制,以防無法定味道還沒渲染出來的元素
try:
elem = driver.find_element_by_css_selector("addthis_sharing_toolbox")
# elem = driver.find_element_by_xpath(Xpath) # 如果你想透過Xpath定位元素
elem.click() # 點擊定位到的元素
except:
time.sleep(2)
count+=1
if(count <2):
tryclick(driver, selector,count)
else:
print("cannot locate element" + selector)
time.sleep(3)
html = driver.page_source
driver.close()
print(html)
作者: ijeffrey 時間: 2018-8-23 14:27
唔係用developer mode ,check 番network request 再睇番D session data?
作者: 清仔 時間: 2018-8-26 11:54
Use Puppeteer
作者: angulardev 時間: 2018-8-30 21:25
我有睇過, 佢都係craw hkjc既資料, 點解你唔直接craw hkjc?
