硒网络刮擦下拉列表
Selenium Web刮擦:
- 下拉列表更改
- 尝试更改结果刮擦
- 失败的
代码:
'''
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
import time
driver=webdriver.Chrome(executable_path=r'C:\Program Files\Python39\chromedriver.exe')
driver.maximize_window()
driver.get("https://www.gastite.com/locator/?cats=109")
for i in range(1,3,1):
state=driver.find_element(By.NAME, 'state')
stateDD=Select(state)
stateDD.select_by_index(i)
driver.find_element(By.XPATH,'//*[@id="content"]/div[3]/form/input[2]')
time.sleep(2)
lists=driver.find_elements_by_css_selector("div.repcontent > a")
#print(lists)
for list in lists:
company=list.find_element_by_class_name('namelink company_title').text
address=list.find_element_by_class_name('address').text
address1=list.find_element_by_class_name('address2').text
tel=list.find_element_by_tag_name('span').text
fax=list.find_element_by_tag_name('span').text
web=list.get_attribute('href')
print(company, address, address1, tel, fax, web)
'''
Selenium web scraping :
- Dropdown list change
- tried to changed results scraping
- failed
Code:
'''
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
import time
driver=webdriver.Chrome(executable_path=r'C:\Program Files\Python39\chromedriver.exe')
driver.maximize_window()
driver.get("https://www.gastite.com/locator/?cats=109")
for i in range(1,3,1):
state=driver.find_element(By.NAME, 'state')
stateDD=Select(state)
stateDD.select_by_index(i)
driver.find_element(By.XPATH,'//*[@id="content"]/div[3]/form/input[2]')
time.sleep(2)
lists=driver.find_elements_by_css_selector("div.repcontent > a")
#print(lists)
for list in lists:
company=list.find_element_by_class_name('namelink company_title').text
address=list.find_element_by_class_name('address').text
address1=list.find_element_by_class_name('address2').text
tel=list.find_element_by_tag_name('span').text
fax=list.find_element_by_tag_name('span').text
web=list.get_attribute('href')
print(company, address, address1, tel, fax, web)
'''
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从下拉列表中选择一个状态进行示例,然后您尝试的其余部分。
I select one state from the dropdownlist for an example and rest of the your attempt.