request.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:spider-lianjia 作者: longxiaofei 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号