TA的每日心情 | 无聊 前天 09:47 |
---|
签到天数: 528 天 连续签到: 1 天 [LV.9]测试副司令
|
1测试积点
先爬取QQ空间日志目录,获取到特定QQ日志后进入日志,爬取日志内容后返回;返回后,运行到跳转到下一页就出错,
next_page = driver.find_element_by_link_text(u'下一页')
page = page + 1
print(QQnum,u'正在抓取日志第%d页面内容······' % page)
next_page.click()
错误信息:<class 'selenium.common.exceptions.NoSuchElementException'> : Message: no such element: Unable to locate element: {"method":"link text","selector":"下一页"}
(Session info: chrome=93.0.4542.2)
主要代码如下;
driver.get('https://user.qzone.qq.com/' + 'qq号' + '/2')
driver.implicitly_wait(5)
time.sleep(2)
- driver.switch_to.frame('app_canvas_frame')
- next_page = 'page'
- page = 1
- try:
- while next_page:
- ele = driver.find_element_by_xpath("//*[@id='listArea']")
- now_handle = driver.current_window_handle
- strs = ele.text.split('\n')
- for x in strs:
- for y in keyworldes:# 关键字
- if y in x:
- log_arr.append(x + '\\' + '第' + str(page) + '页')
- try:
- next_page2 = driver.find_element_by_link_text(x)
- next_page2.click()
- time.sleep(3)
- driver.implicitly_wait(5)
-
- except:
- pass
- driver.back()
- time.sleep(2)
- driver.implicitly_wait(3)
- next_page = driver.find_element_by_link_text(u'下一页')
- page = page + 1
- print(QQnum,u'正在抓取日志第%d页面内容······' % page)
- next_page.click()
- time.sleep(2)
- driver.implicitly_wait(3)
- except:
- info = sys.exc_info()
- print(info[0], ':', info[1])
- print(QQnum,u'抓取到日志第%d页面结束' % page)
复制代码
|
|