我正在做一個與航班價格相關的專案,當我在網上抓取部門時,我得到了錯誤。網址是https://flight.yatra.com/air-search-ui/dom2/trigger?ADT=1&CHD=0&INF=0&class=Economy&destination=BOM&destinationCountry=IN&flexi=0&flight_depart_date=22/01/2022&hb=0&noOfSegments=1&origin=DEL&originCountry= IN&type=O&unique=254010891105&viewName=正常
我的代碼是:
dept_time=driver.find_elements("//div[@class='i-b col-4 no-wrap text-right dtime col-3']")
dept= []
for i in dept_time:
a = i.get_attribute('innerText')
print(a)
dept.append(a)
print(dept)
我也試過 "//div[@class='i-b pr']
但我收到了同樣的錯誤
uj5u.com熱心網友回復:
代替
dept_time=driver.find_elements("//div[@class='i-b col-4 no-wrap text-right dtime col-3']")
嘗試
dept_time=driver.find_elements_by_xpath("//div[@class='i-b col-4 no-wrap text-right dtime col-3']")
或者
dept_time=driver.find_elements(By.XPATH, "//div[@class='i-b col-4 no-wrap text-right dtime col-3']")
此外,不要忘記等待/延遲與您的代碼一起使用,以便在您閱讀其內部文本之前加載元素。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/417732.html
標籤:
