![](/img/trans.png)
[英]Can we login on a website with pure Python urllib, modify some form values, and submit? (without Selenium browser automation)
[英]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.