简体   繁体   English

python硒的问题在哪里?

[英]Where is the problem about selenium with python?

When I run the code it takes about 5-6 sec to execute, after than nothings happens. 当我运行代码时,大约要花5到6秒钟才能执行,什么都没发生。 I get no error, but the code is simply not working. 我没有收到任何错误,但是代码根本无法正常工作。 Please, help me fast I've got a project to do in a month. 拜托,快帮我,我有一个月要做的项目。

from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
opts = Options()
opts.set_headless()
assert opts.headless
browser = Firefox(options=opts)
browser.get("https://duckduckgo.com")

Sorry about not knowing enough about stackoverflow. 对不起,您对stackoverflow的了解不足。 I think I wrote everything to the code entry. 我想我将所有内容都写到了代码条目中。

Your code is perfectly working for me. 您的代码是完全为我工作

opts.set_headless() browser = Firefox(options=opts)

This operation will create an option which hide the browser, then you set this option to you recently created Firefox tab. 此操作将创建一个隐藏浏览器的选项,然后将该选项设置为您最近创建的Firefox选项卡。 Once you open the duckduckgo url, 打开duckduckgo网址后,

It takes a few seconds to you program to open Firefox, but... you reach the end of your program and you browser is HIDING Check with top command and you'll see Firefox still running. 程序打开Firefox需要花费几秒钟,但是...到达程序结尾,浏览器正在使用top命令进行HIDING Check,您将看到Firefox仍在运行。 Try to execute the same code but without the opts.set_headless() line. 尝试执行相同的代码,但不要使用opts.set_headless()行。

Good Luck ! 祝好运 !

Try not use the "headless option": 尝试不使用“无头选项”:

from selenium.webdriver import Firefox
browser = Firefox()
browser.get("https://duckduckgo.com")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM