英文:
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
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论