简体   繁体   中英

Extract Page number from a web page using Python Selenium

i wanted to get the total number of pages in a website. so what i did is that i tried to extract the page number in the bottom to calculate the total pages so that i can traverse using the Next Page Button. Please find the code i tried below :

totpage=driver.find_element_by_xpath("XPATH of the Page Number Shown in the Bottom of the Page")
print(page.text)

but the above code is printing the result as 0 of 0 instead of 1 - 200 of 900

Please find the HTML code below :

<div class="mat-paginator-range-range-label"> 1 - 200 of 900 </div>

i was thinking to to do the calaulation as , page = 900/200 after extracting the number.

what did i do wrong?

is there any alternative way to do this?,

Thanks in Advance

Since you were able to solve 0 of 0 instead of 1 - 200 of 900 with delay. The other half of the problem can be solved by below logic. You should assign the variable that you've (using .text you must have got value 1 - 200 of 900) to actual_count_page .

actual_count_page = " 1 - 200 of 900 "
a = actual_count_page.strip().split(' ')
total_page_count = int(a[4])
max_number_count = int(a[2])

toal_number_of_pages = int(total_page_count/max_number_count)  + 1
print(toal_number_of_pages)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM