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

Selenium-通过 css 抓取网页元素时,同一个版本的 code,结果一个 css 可以识别,另外一个不可以。这是什么原因?

  •  
  •   oooolongtea · 2020-04-12 04:40:03 +08:00 · 1617 次点击
    这是一个创建于 1468 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我正在用 Selenium 测试公司的一个产品。我把这个产品安装到了两个 cluster 上面。这两个 cluster 只有性能上的差别。
    我的 code 其中一步是 Selenium 等待某个页面上的元素消失,然后进行下一步。我用的是这个元素的 css tag 。
    结果是,cluster1 可以识别到这个页面上的元素的消失,cluster2 却不可以。

    为什么会这样?两个 code 是完全一样的,没有区别。
    我手动去验证过,我是可以在两个 cluster 上通过搜索 css 找到这个元素的。
    yejianmail
        1
    yejianmail  
       2020-04-12 09:08:36 +08:00 via Android
    把页面内容输出到控制台对比下,css 选择器不好使就换 id 选择器试试,仔细调试下,你这样的具体问题没有代码,也没有页面的内容大家很难回答
    xuexingdong
        2
    xuexingdong  
       2020-04-12 10:26:38 +08:00
    有可能是加载时间不同导致的,在你程序执行期间,网络性能好的 html 可能直接加载出来了,弱网环境下的可能没有,最好还是在选择器前对浏览器进行截图或者打印一下当时的 html 好排错。
    oooolongtea
        3
    oooolongtea  
    OP
       2020-04-12 11:34:36 +08:00
    @yejianmail @xuexingdong 谢谢两位。因为是公司的代码,我用的也是公司的电脑,我不太敢把代码直接粘贴上来,我怕公司会查到。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5677 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 02:01 · PVG 10:01 · LAX 19:01 · JFK 22:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.