If you want to learn Selenium from scratch, you can read this series of articles!
https://www.cnblogs.com/poloyy/category/1680176.html
Secondly, if you don't know the basic knowledge of the front-end, you need to supplement it yourself. The blogger hasn't summarized it for the moment (although I can, so I don't need to review the front-end when I study selenium...)
Note that the current actual combat is written in the form of daily accounts, which will be combined with the framework + PO mode later
The purpose is to master the Selenium foundation
Actual combat topics
1. Visit: http://www.51job.com
2. Enter the search keyword "python" and select "Beijing" for the region (Note: if other regions have been selected for the location, remove it)
3. Search for the latest posts and grab the page information. Get the following formatting information
Python Development Engineer | Hangzhou Napa Technology Co., Ltd. | Hangzhou | 8-16000 / month | 04-27
Python Senior Development Engineer | China zhexin Technology Consulting Co., Ltd. | Hangzhou | 1-15000 / month | 04-27
Senior Python Development Engineer | Hangzhou new thinking Computer Co., Ltd. | Hangzhou West Lake District | 1-15000 / month | 04-27
Code thinking
- Locate the search box and type python
- Click [region]
- Explicitly wait to locate all selected cities by default
- Uncheck them
- Click [Beijing]
- Click [OK]
- Click search
- Locate position list, except the first line
- Cycle the position list to obtain the information of each line and store it in the list
- Format output
Code (operation steps for human test)
# !/usr/bin/env python # -*- coding: utf-8 -*- """ __title__ = __Time__ = 2020/3/25 17:52 __Author__ = Pineapple test notes __Blog__ = https://www.cnblogs.com/poloyy/ """ from time import sleep from selenium import webdriver from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.common.by import By # Set element to wait for instance for 10 seconds at most, every 0.5 Seconds to find def wait_element(driver, by_, element_, timeout=10): element = WebDriverWait(driver=driver, timeout=timeout).until( lambda x: x.find_element(by=by_, value=element_) ) return element # Set element to wait for instance for 10 seconds at most, every 0.5 Seconds to find def wait_elements(driver, by_, element_, timeout=10): element = WebDriverWait(driver=driver, timeout=timeout).until( lambda x: x.find_elements(by=by_, value=element_) ) return element # Load driver driver = webdriver.Chrome("../resources/chromedriver.exe") # Open web site driver.get("http://www.51job.com") driver.maximize_window() # Search box wait_element(driver, By.CSS_SELECTOR, "#kwdselectid").send_keys("python") # Area button wait_element(driver, By.CSS_SELECTOR, "#work_position_input").click() # Hot cities list city_lists = wait_elements(driver, By.CSS_SELECTOR, "div#work_position_click_center_right_list_000000 td em.on") # Select Beijing and uncheck other cities for city in city_lists: sleep(1) city.click() wait_element(driver, By.CSS_SELECTOR, "em#work_position_click_center_right_list_category_000000_010000").click() # Confirm button driver.find_element_by_css_selector("#work_position_click_bottom_save").click() # Search button click wait_element(driver, By.CSS_SELECTOR, "div.top_wrap button").click() # Position list found lists = wait_elements(driver, By.CSS_SELECTOR, "div#resultList>div.el")[1:] for data in lists: spans = [i.text for i in data.find_elements_by_css_selector("span")] print(" | ".join(spans)) sleep(10) # Exit browser driver.quit()