November 5
Selenium Job 3
Login 51job, HTTP:www.51job.com Enter search keywordsThe Python", Region selection"Hangzhou(Note that if the location is already selected elsewhere, remove it), search for the latest post, and crawl the page information. Get the following formatting informationPython Development Engineer| Hangzhou Napa Technology Co., Ltd.| Hangzhou|0.8- 16,000 /month | Span class= "PL-C1" >04-27python Senior Development Engineer | in Zhejiang Letter Technology Consulting Co., Ltd. | Hangzhou | 1- 15,000 /month | Span class= "PL-C1" >04-27 advanced python development Engineer | Hangzhou New Thinking Computer Co., Ltd. | Hangzhou -West L. District | 1- 15,000 /month | 04-27
Refer to the answer and turn down
Method One
# Coding:utf8From seleniumImport Webdriverdriver= Webdriver. Chrome (R"D:\tools\webdrivers\chromedriver. exe")# Don't forget to set thedriver.implicitly_wait (Ten)# Crawl Information Driver.get (' Http://www.51job.com') driver.find_element_by_id (' Kwdselectid'). Send_keys (' Python‘)# Click Work Location driver.find_element_by_id (' Work_position_input'). Click ()# Select all cities, remove non-Hangzhou and choose Hangzhou,# if it is Hangzhou but no choice, choose these cities cityeles= Driver.find_elements_by_css_selector (' #work_position_click_center_right em‘)For oneIn Cityeles:cityname= One.text Selected= One.get_attribute (' Class‘)# Print Cityname,seletedIf CityName==U' Hangzhou‘:If selected!=' On': One.click ()ElseIf selected==' On': One.click ()# Save 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 Results Analysis Jobs= Driver.find_elements_by_css_selector ( ' #resultList div.el "div at the same class as El, cannot have spaces, indicating & relations for job in jobs: # Remove first line: header row if ' title ' in job.get_ Attribute ( ' Class "): continue Filelds = job.find_elements_by_tag_name ( ' Span= [fileld.text for fileld in Filelds] print ( |
Method Two
# Coding:utf8From seleniumImport Webdriverdriver= Webdriver. Chrome (R"D:\tools\webdrivers\chromedriver. exe") driver.implicitly_wait (Ten) Driver.get (' Http://www.51job.com') driver.find_element_by_id (' Kwdselectid'). Send_keys (' Python') driver.find_element_by_id (' Work_position_input'). Click ()# Choose the city, remove the non-Hangzhou, choose HangzhouSelectedcityeles= Driver.find_elements_by_css_selector (' #work_position_click_center Em[class=on]') for oneIn SelectedCityEles:one.click () driver.find_element_by_id (' work_position_click_center_right_list_category_000000_080200'). Click ()# Save City Selection driver.find_element_by_id (' Work_position_click_bottom_save'). Click () driver.find_element_by_css_selector (' div.ush > Button'). Click ()# Search Results Analysis Jobs = Driver.find_elements_by_css_selector (' #resultList div[class=el]') forjob in jobs: Fields = job.find_elements_by_tag_name (' span') stringfilelds = [field.text- field in Fields] print (' | '. Join (Stringfilelds)) driver.quit ()
Child element Selector
Select the element's child element,
Different from descendant selectors: #choose_car option; option is not necessarily a child element
For example #choose_car > option footer > P; > must be a direct child element
Can be many levels: UL > Ol > Li > Em
Group selection
Group selection Select multiple elements at the same time, comma separated syntax: <s1>,<s2>
Like P,button #food,. Cheese
Combined use
Select all the span child elements with the ID food and all P (including non-food child elements) #food > Span, P- group selected with lowest priority
Select all the span child elements with the ID food and all the P child elements #food > span, #food > P
Select all child elements with ID food #food > *
Brother Node Selection
Select the element immediately following the other element, which has the same parent element, such as #food + div; #many > div > p.special + P immediately following the sibling node
Select the element after the other element, which has the same parent element, such as #food ~ Div, all the sibling nodes
Property Selector
Elements can be selected based on their attributes and attribute values
Like what
*[style]
P[SPEC=LEN2]
p[spec= ' Len2 Len3 '] in the middle of the space, so add quotation marks, no spaces, can be added without
P[spec*= ' Len2 '] #包含
P[spec^= ' len2 '] #开头 end
P[span$= ' Len2 ']
P[CLASS=SPECIAL][NAME=P1] satisfies both properties
Http://www.w3school.com.cn/cssref/css_selectors.asp
P:nth-child (2) Select each <p> element that belongs to the second child element of its parent element
P:nth-last-child (2) ibid., starting with the last child element count.
P:nth-of-type (2) Select each <p> element that belongs to the second <p> element of its parent element
P:nth-last-of-type (2) ibid., but starts counting from the last child element
Verify the CSS selector, click Elements, press CTRL +F
Find #choose_car option[value= ' volvo ' in element tags
Accurate CSS expression in console $$ ("Choose_car option[value= ' Volvo ')"
Some actions of the edit box
Clears the element with the Clear method string Input1.clear ()
Gets the text content entered inside the INPUT element input1.get_attribute (' value ')
Radio Box
The corresponding HTML
<input type= "Radio" name= "Gender" value= "male" > Men <br>
<input type= "Radio" name= "Gender" value= "female" > Women <br>
Click Method Selection
INPUT1 = Driver.find_element (By.css_selector, "Input[value=male]")
Input.click ()
Regardless of whether the element is selected or not, you can ensure that the radio box is selected by clicking on the element directly.
check box
The corresponding HTML
<input type= "checkbox" name= "vehicle" value = "Bike" > I have a bike.
<input type= "checkbox" name= "vehicle" value = "Car" checked> I have a car.
Click Method Selection
Is_selected method to get the selected state
INPUT1 = Driver.find_element (By.css_selector, "Input[value=car]")
Selected = input1_is_selected ()
If selected:
Print (' car already selected ')
Else
Print (' Car not selected,click on it ')
Input1.click ()
check box
The corresponding HTML
<select multiple>
<option value= ' Benz ' > Mercedes S300</option>
<option value= ' accord ' > Accord </option>
</select>
<select>
<option value= "Male" > Men </option>
<option value= "female" selected= "selected" > Women </option>
Select Class
Method Deselect_all
Method Select_by_visible_text
# Coding=utf-8
From selenium import Webdriver
Driver = Webdriver. Chrome (r "D:\tools\webdrivers\chromedriver.exe")
Driver.get (' file:///D:/gsync/workspace/sq/selenium/samples_selenium/wd/lesson04/ms.html ') # Open URL
# import Select
From Selenium.webdriver.support.ui import Select
# Get the appropriate webelement
select = Select (driver.find_element_by_id ("multi"))
# Go ahead and select all the options
Select.deselect_all ()
Select.select_by_visible_text ("accord")
Select.select_by_visible_text ("BMW 740")
# Get the appropriate webelement
select = Select (driver.find_element_by_id ("single"))
Select.select_by_visible_text ("male")
Input (' Press any key to quit ... ')
Driver.quit ()
# Browser Exit
Select, manipulate web elements-3