V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
yezhiye
V2EX  ›  Python

Python selenium find_element_by_xpath 出错

  •  
  •   yezhiye · 2020-02-03 22:20:04 +08:00 · 2613 次点击
    这是一个创建于 1515 天前的主题,其中的信息可能已经有所发展或是发生改变。

    没事在家写 selenium 爬虫,已知第 2 个可用,第 1 个不可用。查了下 xpath 语法没问题啊……求指教

    WebDriverWait(driver,timeout=15).until(lambda d:d.find_element_by_xpath("//div[@class='article']"))

    WebDriverWait(driver,timeout=15).until(lambda d:d.find_element_by_class_name("article"))

    6 条回复    2020-02-04 08:57:07 +08:00
    yezhiye
        1
    yezhiye  
    OP
       2020-02-03 22:33:48 +08:00 via Android
    class 包含多个属性时 xpath 不能这么写,结帖。
    RedisMasterNode
        2
    RedisMasterNode  
       2020-02-03 22:37:37 +08:00   ❤️ 1
    xpath 直接从源码中右键,copy xpath 获取比手写靠谱一点?
    yezhiye
        3
    yezhiye  
    OP
       2020-02-03 22:45:23 +08:00 via Android
    @RedisMasterNode copy path 提供的是很笨的那种,页面稍微变动就用不了了
    ClericPy
        4
    ClericPy  
       2020-02-03 23:45:30 +08:00   ❤️ 1
    1. 没有源码, 不知道你这定位到哪去了
    2. 没有结果, 不知道你说的 find 到的到底是不是 div
    3. selenium 如果不靠谱, 为什么不直接拿整个 HTML 丢给自己家的 lxml 去解析
    wzwwzw
        5
    wzwwzw  
       2020-02-04 02:15:43 +08:00   ❤️ 1
    看看是不是没有切换 iframe。
    yezhiye
        6
    yezhiye  
    OP
       2020-02-04 08:57:07 +08:00 via Android
    感谢楼上各位答复。是我 xpath 写错了,已经解决问题了…
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1062 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 22:42 · PVG 06:42 · LAX 15:42 · JFK 18:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.