[問題] 爬蟲請益-停車場即時資訊已刪文

看板Python作者 (當阿宅才能開R8)時間5年前 (2020/03/13 10:41), 編輯推噓0(001)
留言1則, 1人參與, 5年前最新討論串1/1
練習爬蟲但是有重覆的動作,不知道怎麼寫比較好,所以來請益,謝謝! from selenium import webdriver from pyquery import PyQuery as pq import time driver = webdriver.Chrome() driver.get("https://m.metro.taipei/parkinglotshow.asp") html = driver.find_elements_by_css_selector("#content > table > tbody > tr:nth-child(3) > td:nth-child(1)") nowparknumber = driver.find_elements_by_css_selector("#content > table > tbody > tr:nth-child(3) > td:nth-child(2)") totalparknumber = driver.find_elements_by_css_selector("#content > table > tbody > tr:nth-child(3) > td:nth-child(3)") #content > table > tbody > tr:nth-child(4) > td:nth-child(1) #content > table > tbody > tr:nth-child(4) > td:nth-child(2) #content > table > tbody > tr:nth-child(4) > td:nth-child(3) 這邊跑一次 這邊要跑三次 doc = pq(html) for eachData in html: print(eachData.text) for s in nowparknumber: print(s.text) for t in totalparknumber: print(t.text) 怎麼寫可以讓tr:nth-child(4) > td:nth-child(3) 自己+1呢? 把整個頁面爬完,謝謝! -- 人生的起伏可以追求 不用強求 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.251.66.209 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1584067316.A.97A.html

03/13 17:20, 5年前 , 1F
Beautifulsoup or lxml 用xpath很好處理
03/13 17:20, 1F
文章代碼(AID): #1UQlBqbw (Python)
文章代碼(AID): #1UQlBqbw (Python)