使用Python Selenium在我的Gmail帐户上自动连接
我正在尝试用Python中的Selenium自动登录我的GMail帐户,但我遇到了以下错误:使用Python Selenium在我的Gmail帐户上自动连接,python,selenium,scrapy,Python,Selenium,Scrapy,我正在尝试用Python中的Selenium自动登录我的GMail帐户,但我遇到了以下错误: selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with 我的代码如下所示: #!/usr/bin/python # coding: utf8 import scrapy from seleniu
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
我的代码如下所示:
#!/usr/bin/python
# coding: utf8
import scrapy
from selenium import webdriver
from scrapy.selector import Selector
from selenium.webdriver.common.action_chains import ActionChains
from scrapy.contrib.spiders import CrawlSpider
from scrapy.selector import HtmlXPathSelector
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.http import Request, FormRequest
from scrapy import log
from scrapy.exceptions import DropItem
from scrapy import signals
from selenium.webdriver.common.by import By
import scrapy
from scrapy import signals
from scrapy.http import TextResponse
from scrapy.xlib.pydispatch import dispatcher
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class googleplay(CrawlSpider):
name = "selenium"
flag = True
def __init__(self):
self.driver = webdriver.Firefox()
self.driver.get('http://gmail.com')
action = webdriver.ActionChains(self.driver)
#User name input field identification and data entered
usernametext = self.driver.find_element_by_name('Email')
usernametext.send_keys("myemailaddress@gmail.com") #put your actual username
self.driver.find_element_by_name('signIn').click()
time.sleep(2)
#Password input field identification and data entered
passwordtext = self.driver.find_element_by_name('Passwd')
passwordtext.send_keys("password") #put your actual password
key = self.driver.find_element_by_name('signIn')
print "----------------------"
key.click()
print "----------------------"
start_urls = ["https://www.mywebsite.com"]
def parse(self, reponse):
#Loading the gmail URL
print "toto"
如何解决问题?尝试更改url。使用
https://accounts.google.com/ServiceLogin?service=mail#identifier
而不是http://gmail.com
确保使用原始电子邮件和密码。并将每个元素的self.driver.find_element_by_name
更改为self.driver.find_element_by_id
您的代码将是:
#!/usr/bin/python
# coding: utf8
import scrapy
import time
from selenium import webdriver
from scrapy.selector import Selector
from selenium.webdriver.common.action_chains import ActionChains
from scrapy.contrib.spiders import CrawlSpider
from scrapy.selector import HtmlXPathSelector
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.http import Request, FormRequest
from scrapy import log
from scrapy.exceptions import DropItem
from scrapy import signals
from selenium.webdriver.common.by import By
from scrapy import signals
from scrapy.http import TextResponse
from scrapy.xlib.pydispatch import dispatcher
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class googleplay(CrawlSpider):
name = "selenium"
flag = True
def __init__(self):
self.driver = webdriver.Firefox()
self.driver.get('http://gmail.com')
action = webdriver.ActionChains(self.driver)
#User name input field identification and data entered
usernametext = self.driver.find_element_by_name('Email')
usernametext.send_keys("myemail@gmail.com") #put your actual username
self.driver.find_element_by_name('signIn').click()
#Password input field identification and data entered
passwordtext = self.driver.find_element_by_id('Passwd')
passwordtext.send_keys("mypassword") #put your actual password
self.driver.find_element_by_id('signIn').click()
print "----------------------"
#key.click()
print "----------------------"
start_urls = ["https://www.mywebsite.com"]
def parse(self, reponse):
#Loading the gmail URL
print "toto"
你确定不想为此使用?你尝试过更改url吗?使用
https://accounts.google.com/ServiceLogin?service=mail#identifier
而不是http://gmail.com
我需要使用selenium来删除一些信息,在这些信息经过身份验证后……它对我来说工作正常。您还需要导入时间模块:导入时间
。您还可以尝试更改此行usernametext=self.driver。通过\u id('Email')查找\u元素,并确保使用原始电子邮件和密码。并将每个元素的self.driver.find_element_by_name
更改为self.driver.find_element_by_id
。是的,我的电子邮件和密码都很好。。。如果我更改self.driver.find_element_by_name('signIn')。单击()
byself.driver.find_element_by_id('signIn')。单击()
我会得到相同的错误:`selenium.common.exceptions.ElementNotVisibleException:Message:元素当前不可见,因此可能无法与之交互`