簡體   English   中英

我們可以使用 selenium web 瀏覽器的網站上的搜索功能嗎

[英]Can we use the search functionality on the website using selenium web browser

I am working on the web scraping project in which I want to search the specific element by entering a keyword in the search box of the website using Selenium web driver in Python.

例如,這是網站:www.auchan.fr 我想搜索這個 EAN“4020628743819”號碼。

我嘗試了以下代碼,但它不起作用:

text_area = driver.find_element_by_xpath('//*[@id="search"]/form/input')
text_area.send_keys('4020628743819')
submit_button = driver.find_elements_by_css_selector(".search-submit[type='submit']").submit()

xpath //*[@id="search"]/form/input匹配兩個元素。 搜索欄是第二個,但find_element_by_xpath返回第一個。 您可以通過添加到第一個結果的祖先元素的clone class 來區分並查找沒有此 class 的元素

text_area = driver.find_element_by_xpath('//header[not(contains(@class, "clone"))]//div[@id="search"]//input')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM