硒网刮刮困难吗?

时间:2020-06-17 15:57:20

标签: python html selenium selenium-webdriver instagram

编码新手和最近发现的Web Scraping!我发现这确实可以帮助我进行市场营销实习,并且还认为这将是一个很好的项目!

从本质上讲,我正在尝试创建一个可在instagram上运行的程序,以帮助收集“影响者”,他们的姓名,关注者人数,城市,以及他们的帖子中是否包含诸如“健康”,“健身”之类的特定标签,等。我进行了一些研究,发现了有关硒和使用Web驱动程序的知识,因此我开始进行编码。起初一切正常,我可以打开Safari浏览器,但是现在登录困难。

这是我收到的错误:

---------------------------------------------------------------------------
ElementNotVisibleException                Traceback (most recent call last)
<ipython-input-3-6ec476894621> in <module>
      9 sleep(2)
     10 username_input = browser.find_element_by_name('username')
---> 11 username_input.send_keys("test_research")
     12 
     13 sleep(2)

/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py in send_keys(self, *value)
    477         self._execute(Command.SEND_KEYS_TO_ELEMENT,
    478                       {'text': "".join(keys_to_typing(value)),
--> 479                        'value': keys_to_typing(value)})
    480 
    481     # RenderedWebElement Items

/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py in _execute(self, command, params)
    631             params = {}
    632         params['id'] = self._id
--> 633         return self._parent.execute(command, params)
    634 
    635     def find_element(self, by=By.ID, value=None):

/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py in execute(self, driver_command, params)
    319         response = self.command_executor.execute(driver_command, params)
    320         if response:
--> 321             self.error_handler.check_response(response)
    322             response['value'] = self._unwrap_value(
    323                 response.get('value', None))

/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py in check_response(self, response)
    240                 alert_text = value['alert'].get('text')
    241             raise exception_class(message, screen, stacktrace, alert_text)
--> 242         raise exception_class(message, screen, stacktrace)
    243 
    244     def _value_or_default(self, obj, key, default):

ElementNotVisibleException: Message: An element command could not be completed because the element is not visible on the page.

我对HTML进行了三倍检查,似乎我使用的是正确的名称,但是由于某种原因,我的程序找不到用户名或密码框并输入信息。任何和所有帮助将不胜感激。以下是我的尝试代码。

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

browser = webdriver.Safari()

browser.get('https://www.instagram.com/accounts/login/')

sleep(2)
username_input = browser.find_element_by_name('username')
username_input.send_keys("******")

sleep(2)
password_input = browser.find_element_by_name('password')
password_input.send_keys("******")

login_button = browser.find.element_by_name('//
[@id="reactroot"]/section/main/div/article/div/div[1]/div/form/div[4]')
login_button.click()

下面是用户名框的HTML

<label class="f0n8F "><span class="_9nyy2">Phone number, username, or email</span><input aria-label="Phone number, username, or email" aria-required="true" autocapitalize="off" autocorrect="off" maxlength="75" name="username" type="text" class="_2hvTZ pexuQ zyHYP" value=""></label>

下面是密码框的HTML

<label class="f0n8F "><span class="_9nyy2">Password</span><input aria-label="Password" aria-required="true" autocapitalize="off" autocorrect="off" name="password" type="password" class="_2hvTZ pexuQ zyHYP" value=""></label>

这也是登录按钮

<div class="                    Igw0E     IwRSH      eGOV_         _4EzTm    bkEs3                          CovQj                  jKUp7          DhRcB                                                    "><button class="sqdOP  L3NKy   y3zKF     " disabled="" type="submit"><div class="                    Igw0E     IwRSH      eGOV_         _4EzTm                                                                                                              ">Log In</div></button></div>

0 个答案:

没有答案