InvalidArgumentException:消息:无效参数:无效定位器错误即将到来
InvalidArgumentException: Message: invalid argument: invalid locator error coming
我正在做一个与航班价格相关的项目,当我尝试网络抓取部门时我得到了错误。
url 是 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%2F01%2F2022&hb=0&noOfSegments=1&origin=DEL&originCountry=IN&type=O&unique=254010891105&viewName=normal
我的代码是:
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']
但我收到了同样的错误
而不是
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']")
此外,不要忘记在您的代码中使用等待/延迟来让元素在您阅读其内部文本之前加载。
我正在做一个与航班价格相关的项目,当我尝试网络抓取部门时我得到了错误。 url 是 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%2F01%2F2022&hb=0&noOfSegments=1&origin=DEL&originCountry=IN&type=O&unique=254010891105&viewName=normal
我的代码是:
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']
但我收到了同样的错误
而不是
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']")
此外,不要忘记在您的代码中使用等待/延迟来让元素在您阅读其内部文本之前加载。