Selenium是慢的还是我的代码错了? [英] Is Selenium slow, or is my code wrong?

查看:134
本文介绍了Selenium是慢的还是我的代码错了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试使用Python登录Quora,然后刮掉一些东西。

So I'm trying to login to Quora using Python and then scrape some stuff.

我正在使用Selenium登录该网站。这是我的代码:

I'm using Selenium to login to the site. Here's my code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get('http://www.quora.com/')

username = driver.find_element_by_name('email')
password = driver.find_element_by_name('password')

username.send_keys('email')
password.send_keys('password')
password.send_keys(Keys.RETURN)

driver.close()

现在问题:


  1. 查找并填写登录表单花了大约4分钟,这非常缓慢。我有什么办法可以加快这个过程吗?

  1. It took ~4 minutes to find and fill the login form, which painfully slow. Is there something I can do to speed up the process?

当它登录时,我该如何确保没有错误?换句话说,如何查看响应代码?

When it did login, how do I make sure there were no errors? In other words, how do I check the response code?

如何使用selenium保存cookie,以便我可以在登录后继续抓取?

How do I save cookies with selenium so I can continue scraping once I login?

如果没有办法让硒更快,是否还有其他办法登录? (Quora没有API)

If there is no way to make selenium faster, is there any other alternative for logging in? (Quora doesn't have an API)


推荐答案

我有一个类似的使用ChromeDriver在Python selenium中调用非常慢的find_elements_xxx的问题。我最终找到了我在find_element_xxx()调用之前调用的driver.implicitly_wait()调用的麻烦;当我拿出它时,我的find_element_xxx()调用很快就会运行。

I had a similar problem with very slow find_elements_xxx calls in Python selenium using the ChromeDriver. I eventually tracked down the trouble to a driver.implicitly_wait() call I made prior to my find_element_xxx() calls; when I took it out, my find_element_xxx() calls ran quickly.

现在,当我执行find_elements_xxx时,我知道那些元素在那里( )电话。所以我无法想象为什么implicit_wait应该影响这些操作的速度,但确实如此。

Now, I know those elements were there when I did the find_elements_xxx() calls. So I cannot imagine why the implicit_wait should have affected the speed of those operations, but it did.

这篇关于Selenium是慢的还是我的代码错了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆