def get_total_page(browser, url):
browser.get(url)
try:
time.sleep(4)
total_room = browser.find_element_by_xpath('/html/body/div[4]/div[1]/div[2]/h2/span').text
if not total_room:
return None
if int(total_room) <= 30:
return 1
total = WebDriverWait(browser, 30).until(
EC.presence_of_element_located((By.XPATH, "/html/body/div[4]/div[1]/div[7]/div[2]/div/a[last()]"))
)
if not total.text.isdigit():
total_page = browser.find_element_by_xpath('/html/body/div[4]/div[1]/div[7]/div[2]/div/a[last()-1]').text
else:
total_page = total.text
return total_page
except TimeoutException as e:
print('????????25??????')
time.sleep(25)
return get_total_page(url)
评论列表
文章目录