Selenium-51Job Automation Test (CSS Selector Select Element)

Log in to 51job,
http://www.51job.com

Enter the search keyword “python”, select the region “Hangzhou” (note that if the location has already selected other regions , To be removed),
Search for the latest posts, and grab page information. Get the following formatting information

Python development engineer | Hangzhou Napa Technology Co., Ltd. | Hangzhou | 0.8-16,000/month | 04-27
Python senior development engineer | Zhongzhexin Technology Consulting Co., Ltd. Company| Hangzhou| 1-1.5 million/month| 04-27
Senior Python Development Engineer| Hangzhou New Thinking Computer Co., Ltd.| Hangzhou-Xihu District| 1-1.5 million/month| 04-27

from selenium import webdriverdriver = 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#Print city name selected = city.get_attribute('class')=='on'#Judge if (cityName =='Hangzhou'and not selected)or\ ( cityName !='Hangzhou' and selected):#The city name is Hangzhou not clicked or the city name is not Hangzhou was clicked city.click()# Save the city selection driver.find_element_by_id('work_position_click_bottom_save').click()# Click to search driver.find_element_by_css_selector('.ush button').click()# Search result analysis jobs = drive r.find_elements_by_css_selector('#resultList div.el')for job in jobs: # Remove the first line: title line 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()

Leave a Comment

Your email address will not be published.