各位高手:本人小白,最近在學習爬蟲技術,以攜程網機票作為起步對象。 過程中發現使用子標簽函數并不能返回所有的子標簽內容(如圖),父標簽是內容是<div class='flight-list">, 四個子標簽內容均為 <div class>...</div> ,但實際能夠取數的只有前兩個,請問這是為什么,并如何解決呢?感激不盡!代碼:from selenium import webdriverfrom bs4 import BeautifulSoupimport timebrower = webdriver.PhantomJS(executable_path='D:/phantomjs-2.1.1-windows/phantomjs-2.1.1-windows/bin/phantomjs')try:? html_infor = brower.get("https://flights.ctrip.com/itinerary/roundtrip/KHH-WUH?date=2018-11-21,2018-11-21&portingToken=570b1bdc855c4eaba0654eb83e9923f7")? time.sleep(20)? pageSource = brower.page_source ###網頁加載信息的實體化? bsObj = BeautifulSoup(pageSource)? ###放進美湯? for child in bsObj.find("div",{"class":"flight-list"}).children:??? print(child)finally:??? brower.close()
1 回答

MyFray
TA貢獻2條經驗 獲得超0個贊
上面的格式太亂了,代碼我在這里重新打一下
for?i?in?range(20): ????js?=?"var?q=document.documentElement.scrollTop={}" ????js?=?js.format((i+1)?*?400) ????self.driver.execute_script(js) ????time.sleep(0.1)
添加回答
舉報
0/150
提交
取消