51Testing软件测试论坛
标题:
Python+Selenium back()返回后运行driver.find_element_by_link_text(u'下一页')报错
[打印本页]
作者:
测试积点老人
时间:
2021-8-2 14:04
标题:
Python+Selenium back()返回后运行driver.find_element_by_link_text(u'下一页')报错
先爬取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)
复制代码
作者:
qqq911
时间:
2021-8-3 10:25
明显定位有问题
作者:
bellas
时间:
2021-8-3 12:19
重新换下路径
作者:
jingzizx
时间:
2021-8-3 13:29
有没有定位到
作者:
海海豚
时间:
2021-8-3 14:34
换一种定位方式,重新定位
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2