• 输入页码实现翻页跳转


    try:
    self.browser.get(request.url)
    if page > 1:
    print(page)
    # input = self.wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '# J_bottomPage > span.p-skip > input')))
    # input.clear()
    # input.send_keys(page)
    # time.sleep(5)
    '''
    模拟点击下一页
    '''
    # fp_next = self.browser.find_element_by_xpath('//*[@id = "J_bottomPage"]/span[1]/a[9]/em')
    # # fp_next = browser.find_element_by_css_selector('a.fp-next')
    # # 点击下一页
    # fp_next.click()

    # 将网页中输入跳转页的输入框赋值给input变量 EC.presence_of_element_located,判断输入框已经被加载出来
    #input = self.wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '# J_bottomPage > span.p-skip > input')))
    input = self.browser.find_element_by_css_selector('span.p-skip input')
    input.clear()
    input.send_keys(page)
    print('成功输入页码')
    print('************************')
    # 将网页中调准页面的确定按钮赋值给submit变量,EC.element_to_be_clickable 判断此按钮是可点击的
    #submit = self.wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '# J_bottomPage > span.p-skip > a')))
    submit = self.browser.find_element_by_css_selector('span.p-skip a')
    submit.click() # 点击按钮
    time.sleep(5)
    print('成功点击下一页')
    print('************************')
    time.sleep(15)

    # 判断当前页码出现在了输入的页面中,EC.text_to_be_present_in_element 判断元素在指定字符串中出现
    #self.wait.until(EC.text_to_be_present_in_element((By.CSS_SELECTOR, '#J_bottomPage > span.p-num > a.curr'),str(page)))
    # 等待 #J_goodsList 加载出来,为页面数据,加载出来之后,在返回网页源代码
    #self.wait.until(EC.text_to_be_present_in_element((By.CSS_SELECTOR, '#J_bottomPage > span.p-num > a.curr'),str(page)))
    print(request.url)
    return HtmlResponse(url=request.url, body=self.browser.page_source, request=request, encoding='utf-8',status=200)
    except TimeoutException:
    return HtmlResponse(url=request.url, status=500, request=request)
  • 相关阅读:
    SqlServer添加链接数据库
    Sqlserver2016下载
    【刷题】【lca】运输计划
    【刷题】【图论】信息传递
    【刷题】【秦九昭式】解方程
    【刷题】【最短路】【k点中最小两点间距离】Senior Pan
    【刷题】【贪心】【国王游戏】
    【刷题】【贪心】观光公交
    【刷题】【bfs】最优贸易
    【笔记】【线段树】矩形面积交 矩形周长
  • 原文地址:https://www.cnblogs.com/liuffblog/p/12713531.html
Copyright © 2020-2023  润新知