Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在Angular网站上查找用于搜索的Xpath_Python_Html_Selenium_Screen Scraping - Fatal编程技术网

Python 如何在Angular网站上查找用于搜索的Xpath

Python 如何在Angular网站上查找用于搜索的Xpath,python,html,selenium,screen-scraping,Python,Html,Selenium,Screen Scraping,我想用python在angular网站上进行自动搜索。在通过Xpath成功测试了简单Google搜索的搜索字段标识之后,我很难找到以下html的正确Xpath。蓝色的html行,我希望在这行上有Xpath 全文如下: <div class="input-group"> <input autofocus="" class="form-control ng-pristine ng-valid ng-touched&qu

我想用python在angular网站上进行自动搜索。在通过Xpath成功测试了简单Google搜索的搜索字段标识之后,我很难找到以下html的正确Xpath。蓝色的html行,我希望在这行上有Xpath

全文如下:

<div class="input-group">
      <input autofocus="" class="form-control ng-pristine ng-valid ng-touched" formcontrolname="term" type="search" placeholder="Suchen">
    </div>
为什么这些都不起作用?什么有效,为什么有效?

固定代码:

search_input_locator = "//input[@placeholder='Suchen']"
search_button_locator = "//button[text()='Suchen']"

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH,search_input_locator)))
driver.find_element_by_xpath(search_input_locator).send_keys('AYT')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH,search_button_locator)))
driver.find_element_by_xpath(search_button_locator).click()
你的错误:

  • @class='form-control auto complete ng pristine ng valid ng valid editable ng empty ng toucted'
    -对类使用严格比较是一种不好的做法,因为它更改太频繁。让我们使用这样的东西
    /*[包含(@class,'one\u class\u name')]
  • 错误的定位器
    //div[text()='Suchen']
    ,正确:
    //按钮[text()='Suchen']
  • 固定代码:

    search_input_locator = "//input[@placeholder='Suchen']"
    search_button_locator = "//button[text()='Suchen']"
    
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH,search_input_locator)))
    driver.find_element_by_xpath(search_input_locator).send_keys('AYT')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH,search_button_locator)))
    driver.find_element_by_xpath(search_button_locator).click()
    
    你的错误:

  • @class='form-control auto complete ng pristine ng valid ng valid editable ng empty ng toucted'
    -对类使用严格比较是一种不好的做法,因为它更改太频繁。让我们使用这样的东西
    /*[包含(@class,'one\u class\u name')]
  • 错误的定位器
    //div[text()='Suchen']
    ,正确:
    //按钮[text()='Suchen']

  • 要开始,请确保您正在使用Chrome浏览器。查看源代码时,右键单击元素(在本例中为
    标记,然后执行复制>复制XPath)


    要开始,请确保您正在使用Chrome浏览器。在查看源代码时,右键单击元素(在本例中为
    标记,然后执行复制>复制XPath)


    < /P>代码不起作用。考虑将它提供在文本格式。部分或整个HTML作为文本。添加的部分是ITSY,或链接到巴斯丁,这样用户就可以很容易地测试。代码的图片没有帮助。考虑将它提供在文本格式。部分或整个HTML作为文本?添加的部分是ITYES,或者链接到巴斯宾,这样用户就可以轻松地进行TES。T