Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.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 点击带有图像的按钮_Python_Html_Selenium_Web Scraping_Web Crawler - Fatal编程技术网

Python 点击带有图像的按钮

Python 点击带有图像的按钮,python,html,selenium,web-scraping,web-crawler,Python,Html,Selenium,Web Scraping,Web Crawler,我正在尝试爬网此页面: 我做了这个剧本 from selenium import webdriver URL = "http://www.1800contractor.com/d.GA.html" zip_codes = ['30324'] driver = webdriver.Firefox() driver.get(URL) zip_codes = ['30324'] text_box = driver.find_element_by_xpath('//*[@id="zip"]')

我正在尝试爬网此页面:

我做了这个剧本

from selenium import webdriver


URL = "http://www.1800contractor.com/d.GA.html"
zip_codes = ['30324']

driver = webdriver.Firefox()
driver.get(URL)

zip_codes = ['30324']
text_box = driver.find_element_by_xpath('//*[@id="zip"]')
text_box.send_keys(zip_codes[0])        
button = driver.find_element_by_xpath('//*[@id="xmdListingsSearchForm"]')
button.click()
基本上,我需要在搜索框中输入邮政编码:

zip_codes = ['30324']
text_box = driver.find_element_by_xpath('//*[@id="zip"]')
text_box.send_keys(zip_codes[0])
那部分正在发挥作用

然后单击“开始”按钮:

button = driver.find_element_by_xpath('//*[@id="xmdListingsSearchForm"]')
button.click()
该部分不起作用,这是我在该按钮的html中看到的:

<input type="image" src="/rfs/servicerequest/images/go_btn_grey_20x20.gif" height="20" width="20" style="position: relative; top: 1px;">


因此,我想问题是我没有得到实际按钮的参考,而是按钮图像的参考。

有一种更简单的解决方法-在邮政编码末尾发送换行符-它会自动提交表单:

text_box.send_keys(zip_codes[0] + "\n")
对我有用

如果您坚持单击按钮/“按钮图像”,您可以使用以下CSS选择器来定位它,该选择器匹配
src
属性值的一部分,并尝试保持其可读性:

driver.find_element_by_css_selector("input[src*=go_btn]").click()