推荐学习书目
› 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 · Apr 12, 2020 · 2640 views
    This topic created in 2357 days ago, the information mentioned may be changed or developed.
    我正在用 Selenium 测试公司的一个产品。我把这个产品安装到了两个 cluster 上面。这两个 cluster 只有性能上的差别。
    我的 code 其中一步是 Selenium 等待某个页面上的元素消失,然后进行下一步。我用的是这个元素的 css tag 。
    结果是,cluster1 可以识别到这个页面上的元素的消失,cluster2 却不可以。

    为什么会这样?两个 code 是完全一样的,没有区别。
    我手动去验证过,我是可以在两个 cluster 上通过搜索 css 找到这个元素的。
    yejianmail
        1
    yejianmail  
       Apr 12, 2020 via Android
    把页面内容输出到控制台对比下,css 选择器不好使就换 id 选择器试试,仔细调试下,你这样的具体问题没有代码,也没有页面的内容大家很难回答
    xuexingdong
        2
    xuexingdong  
       Apr 12, 2020
    有可能是加载时间不同导致的,在你程序执行期间,网络性能好的 html 可能直接加载出来了,弱网环境下的可能没有,最好还是在选择器前对浏览器进行截图或者打印一下当时的 html 好排错。
    oooolongtea
        3
    oooolongtea  
    OP
       Apr 12, 2020
    @yejianmail @xuexingdong 谢谢两位。因为是公司的代码,我用的也是公司的电脑,我不太敢把代码直接粘贴上来,我怕公司会查到。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2493 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 01:38 · PVG 09:38 · LAX 18:38 · JFK 21:38
    ♥ Do have faith in what you're doing.