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
j0shfan
V2EX  ›  Python

Selenium 爬网页的问题, css selector

  •  
  •   j0shfan · 2020-08-11 11:38:17 +08:00 · 1578 次点击
    这是一个创建于 1351 天前的主题,其中的信息可能已经有所发展或是发生改变。
    大佬们,我想爬个网页练练手,现在碰到问题了,目标无法被 CSS 选择器选中,麻烦看下问题出在哪里
    网页是这样的
    <ul>
    <type=1><start=1>
    <li><a href="Papers/XXX.pdf">Preface</a></li>
    <li><a href="Papers/XXX.pdf">Chapter 1</a></li>

    使用 find_element_by_css_selector 可以选中到 ul 这里
    但是再往下 type=1 start=1 怎样都无法选中( ul > type=1 > start=1 )
    想问下问题出在哪里
    6 条回复    2020-08-11 21:55:50 +08:00
    yejianmail
        1
    yejianmail  
       2020-08-11 13:15:38 +08:00 via Android
    不行就试试 xpath 选择器吧
    jeeyong
        2
    jeeyong  
       2020-08-11 13:22:23 +08:00
    type=1 这个不是元素就是个空标签 属性是 type 值=1
    你非得选这个
    试试 find
    j0shfan
        3
    j0shfan  
    OP
       2020-08-11 13:35:16 +08:00
    @yejianmail 一样选不中,捂脸
    j0shfan
        4
    j0shfan  
    OP
       2020-08-11 14:00:44 +08:00
    @jeeyong 实际我想批量选的是 a href 后面那个文件的连接。
    请问 find 是个什么概念,是 find_element(s)吗
    tikazyq
        5
    tikazyq  
       2020-08-11 14:03:43 +08:00
    用 puppeteer,直接 js 操作,比 selenium 简单很多
    jeeyong
        6
    jeeyong  
       2020-08-11 21:55:50 +08:00
    不是...之前回复的时候再打 pubg...
    你这<type=1>是什么标签啊?
    没有这种标签啊...这个根本写错了吧..
    还是你爬取的场景遇到这种情况了?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1026 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:09 · PVG 04:09 · LAX 13:09 · JFK 16:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.