码迷,mamicode.com
首页 > Web开发 > 详细

selenium-51job自动化测试(css选择器选择元素)

时间:2019-06-29 15:08:47      阅读:364      评论:0      收藏:0      [点我收藏+]

标签:sele   nts   get   搜索   NPU   css选择器   python   自动化   attribute   

登录 51job ,
http://www.51job.com

输入搜索关键词 "python", 地区选择 "杭州"(注意,如果所在地已经选中其他地区,要去掉),
搜索最新发布的职位, 抓取页面信息。 得到如下的格式化信息

Python开发工程师 | 杭州纳帕科技有限公司 | 杭州 | 0.8-1.6万/月 | 04-27
Python高级开发工程师 | 中浙信科技咨询有限公司 | 杭州 | 1-1.5万/月 | 04-27
高级Python开发工程师 | 杭州新思维计算机有限公司 | 杭州-西湖区 | 1-1.5万/月 | 04-27

 

 

from selenium import webdriver
driver = webdriver.Chrome(r"D:\for myself\Google\Chrome\Application\chromedriver.exe")
driver.implicitly_wait(10)
driver.get(‘http://www.51job.com‘)
driver.find_element_by_id(‘kwdselectid‘).send_keys(‘python‘)
driver.find_element_by_id(‘work_position_input‘).click()
cityEles = driver.find_elements_by_css_selector(‘#work_position_click_center_right_list_000000 em‘)
for city in cityEles:
cityName = city.text#打印城市名字
selected = city.get_attribute(‘class‘)==‘on‘#判断
if (cityName == ‘杭州‘and not selected)or\
(cityName !=‘杭州‘ and selected):#城市名字是杭州没有被点击或者城市名字不是杭州被点击了
city.click()
# 保存城市选择
driver.find_element_by_id(‘work_position_click_bottom_save‘).click()

# 点击搜索
driver.find_element_by_css_selector(‘.ush button‘).click()

# 搜索结果分析
jobs = driver.find_elements_by_css_selector(‘#resultList div.el‘)

for job in jobs:
# 去掉第一行:标题行
if ‘title‘ in job.get_attribute(‘class‘):
continue

filelds = job.find_elements_by_tag_name(‘span‘)
strField = [fileld.text for fileld in filelds]
print (‘ | ‘.join(strField))


driver.quit()

 

 

 

 

 

 

 

 

 

 

 

 

 

 

selenium-51job自动化测试(css选择器选择元素)

标签:sele   nts   get   搜索   NPU   css选择器   python   自动化   attribute   

原文地址:https://www.cnblogs.com/iamshasha/p/11106376.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!