只通过调试Selenium提供数据。

huangapple go评论59阅读模式
英文:

Gives data only through debugging selenium

问题

我有一个问题,我有一段代码

browser1.get("https://www.artstation.com/artwork/LeAN1P")

element = browser1.find_elements(by=By.CSS_SELECTOR, value='div.d-flex:nth-child(2) > span:nth-child(2)')
for el in element:
print(el.text)


我需要获取"Views"参数,但是尽管代码成功执行,但一切都以成功执行结束,尽管如果您通过调试运行它,那么一切都正常工作

[调试控制台][1]

[运行控制台][2]

如果将代码集成到另一个项目中,那么会弹出错误,请告诉我如何从这个页面获取"Views"文本数据
[在另一个完成的项目中运行][3]

请帮忙,没有思路

  [1]: https://i.stack.imgur.com/EOfuG.png
  [2]: https://i.stack.imgur.com/IPW1a.png
  [3]: https://i.stack.imgur.com/faAei.png
英文:

I have a problem, I have a code

browser1.get("https://www.artstation.com/artwork/LeAN1P")


element = browser1.find_elements(by=By.CSS_SELECTOR, value='div.d-flex:nth-child(2) >  span:nth-child(2)')
for el in element:
    print(el.text)

I need to get the Views parameter, but everything ends with the successful execution of the code, despite the fact that if you run it through debug, then everything works

Debug console

Run console

if you integrate the code into another, then an error pops up, tell me how you can get the Views text data from this page
launch in another finished project

no ideas please help

答案1

得分: 0

你的元素在脚本运行模式下简单地没有加载,因为它比调试更快。在查找元素之前,等待它被定位/可见等。
https://selenium-python.readthedocs.io/waits.html

英文:

Your elements are simply not loaded yet when script in run mode, as it's faster than debug. Before finding element wait for it to be located/visible etc
https://selenium-python.readthedocs.io/waits.html

huangapple
  • 本文由 发表于 2023年1月9日 01:54:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75050111.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定