m0_57965808 2021-10-17 21:47 采纳率: 90.9%
浏览 75
已结题

Python selenium帮运行一下代码

代码报错,想换台电脑试试能不能运行成功,用户名和密码出于保密考虑就不写我自己的了。代码如下:

from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get('https://wenku.baidu.com/view/83a62ad5316c1eb91a37f111f18583d048640f3c')
time.sleep(5)
elements=driver.find_elements_by_class_name('read-all')#继续阅读
element=elements[0]
#print(element)
element.click()
time.sleep(5)
yhm=driver.find_elements_by_css_selector('#TANGRAM__PSP_11__footerULoginBtn')#用户名登录
#print(yhm)
yhmd=yhm[0]
yhmd.click()
yh=driver.find_elements_by_css_selector('#TANGRAM__PSP_11__userName')#用户名
#print(yh)
yh=yh[0]
yh.send_keys('sssss')
mm=driver.find_elements_by_css_selector('#TANGRAM__PSP_11__password')#密码
mm=mm[0]
mm.send_keys('123')
dl=driver.find_elements_by_css_selector('#TANGRAM__PSP_11__submit')#点击登录按钮
dl=dl[0]
dl.click()
time.sleep(30)
gk=driver.find_element_by_class_name('close-btn default-bg')#关闭广告
#gkc=gk[0]
gk.click()
zc=driver.find_elements_by_class_name('read-all')#再次点击继续阅读
zcc=zc[0]
zcc.click()
xt=driver.find_elements_by_class_name("reader-word-layer")爬取文章内容
for i in xt:
    i=i+i
    print(i.text)
 


  • 写回答

1条回答 默认 最新

  • 辉煌仪奇 2021-10-18 02:32
    关注

    你好运行结果出来了,不过中间有图片过检测没有过,在登陆后有验证码没有过

    img

    img

    img


    登录后程序报错

    G:\AQ\main.py:796: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
      driver = webdriver.Chrome(executable_path = 'C:\Program Files\Google\Chrome\Application\chromedriver.exe')
    G:\AQ\main.py:800: DeprecationWarning: find_elements_by_* commands are deprecated. Please use find_elements() instead
      elements = driver.find_elements_by_class_name('read-all')  # 继续阅读
    G:\AQ\main.py:805: DeprecationWarning: find_elements_by_* commands are deprecated. Please use find_elements() instead
      yhm = driver.find_elements_by_css_selector('#TANGRAM__PSP_11__footerULoginBtn')  # 用户名登录
    G:\AQ\main.py:809: DeprecationWarning: find_elements_by_* commands are deprecated. Please use find_elements() instead
      yh = driver.find_elements_by_css_selector('#TANGRAM__PSP_11__userName')  # 用户名
    G:\AQ\main.py:813: DeprecationWarning: find_elements_by_* commands are deprecated. Please use find_elements() instead
      mm = driver.find_elements_by_css_selector('#TANGRAM__PSP_11__password')  # 密码
    G:\AQ\main.py:816: DeprecationWarning: find_elements_by_* commands are deprecated. Please use find_elements() instead
      dl = driver.find_elements_by_css_selector('#TANGRAM__PSP_11__submit')  # 点击登录按钮
    G:\AQ\main.py:820: DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead
      gk = driver.find_element_by_class_name('close-btn default-bg')  # 关闭广告
    Traceback (most recent call last):
      File "G:\AQ\main.py", line 820, in <module>
        gk = driver.find_element_by_class_name('close-btn default-bg')  # 关闭广告
      File "G:\AQ\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 754, in find_element_by_class_name
        return self.find_element(by=By.CLASS_NAME, value=name)
      File "G:\AQ\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1238, in find_element
        return self.execute(Command.FIND_ELEMENT, {
      File "G:\AQ\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 418, in execute
        self.error_handler.check_response(response)
      File "G:\AQ\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".close-btn default-bg"}
      (Session info: chrome=94.0.4606.81)
    Stacktrace:
    Backtrace:
        Ordinal0 [0x004EBDE3+2473443]
        Ordinal0 [0x00486661+2057825]
        Ordinal0 [0x00392438+1057848]
        Ordinal0 [0x003BC7DB+1230811]
        Ordinal0 [0x003E6712+1402642]
        Ordinal0 [0x003D571A+1333018]
        Ordinal0 [0x003E4ABF+1395391]
        Ordinal0 [0x003D55AB+1332651]
        Ordinal0 [0x003B2104+1188100]
        Ordinal0 [0x003B2F59+1191769]
        GetHandleVerifier [0x00672266+1549718]
        GetHandleVerifier [0x0071D4A7+2250711]
        GetHandleVerifier [0x0057718B+521403]
        GetHandleVerifier [0x00576229+517465]
        Ordinal0 [0x0048B79D+2078621]
        Ordinal0 [0x0048FB58+2095960]
        Ordinal0 [0x0048FC92+2096274]
        Ordinal0 [0x00499541+2135361]
        BaseThreadInitThunk [0x753CFA29+25]
        RtlGetAppContainerNamedObjectPath [0x77557A9E+286]
        RtlGetAppContainerNamedObjectPath [0x77557A6E+238]
    
    
    进程已结束,退出代码为 1
    

    有帮助请采纳,有问题继续交流,你的采纳是对我回答的最大的肯定和动力

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 10月20日
  • 已采纳回答 10月18日
  • 创建了问题 10月17日

悬赏问题

  • ¥20 Yolov5训练报错
  • ¥15 Unity发布gzip压缩的webgl之后让浏览器可以正常显示画面
  • ¥15 有没有人知道这种提示怎么关?现在不做ts项目了不知道咋关了,求解,现在我以前的js项目都是这种提示了
  • ¥15 为什么mysql做了碎片化处理data_free还是很高
  • ¥15 single positional indexer is out-of-bounds
  • ¥15 LSTM 模型数据量需要多少?
  • ¥15 mysql数据抓包开发报表
  • ¥15 linux系统下安装office打不开
  • ¥20 rsync脚本分发错误,文件不齐全
  • ¥15 labview顺序结构与时间延时