Most of the time, the layout on the page is in tabular form, such as the following
This type of Web page in the automation of the headache, need a lot of judgment, below for example, here to Shenzhen entry-Exit page for example, http://yysl.sz3e.com/wsyysq/select_sldw_zbs.jsp
For example, we need to click on any one of the Saturday can be an appointment time, how to write it.
First of all we want to analyze, this is also the first step to write a program, the manual operation of the logical extraction, and then form a program
1, first determine the date in the list, find the Saturday column
2, and then from the found column to determine the time of the appointment of the point
The basic idea is this, to see the 1th, how to extract the table-style date and time?
Use Firepath to see
So you can use current to find all the Id,xpath://label[@class = ' current ']
How do you figure out a list of data?
As you can see from the HTML, this is a standard form of a form
You can use the following methods to locate a column of data
//tbody[@id = ' timeline ']/tr/td[1] where 1 represents the 1th column, the corresponding column can be taken out as needed
The basic code is as follows:
All_data=browser.find_elements (By.xpath,"//label[@class = ' current ']")#Select all date element pairs likeRowall=[rowall.text forRowallinchAll_data]#take out the corresponding date elementrowindex=[rowall.index (i) forIinchRowallifU'Saturday' inchI#Get column" "determine if Saturday can be scheduled, no 2s refresh" " whileTrue:tds=browser.find_elements (By.xpath,"//tbody[@id = ' timeline ']/tr/td[%d]"% (rowindex[0]+1)) if[TD forTdinchTdsif "Reservations Available" inchTd.text]: Break Else: Browser.find_element_by_xpath ("//span[@receivepointsid = ' 440307000000 ')"). Click () time.sleep (2).....
Python Selenium manipulating table-style element instances