Forums

impossible using selenium with instagram

Hello guys, i'm a student and i'm douing a project for the exam.

I tried in any way possible but i can't get my code to run, whit some other sites it works, but with instagram don't. What I'm doing wrong?

I did also a "Hacker" account just to run my project, then i guess that it's not a power problem

anyway my start code is:

from pyvirtualdisplay import Display
from selenium import webdriver
from time import sleep



with Display():
     browser = webdriver.Firefox()


try:
    browser.get('https://www.instagram.com')
    print("get instagram.com ")

    browser.implicitly_wait(60)
    browser.find_element_by_link_text('Log in').click()
    print("click log in")
    sleep(10)

 finally:
    browser.quit()

the error seems because it can't fine the element but I'm sure that my code works

get instagram.com 
Traceback (most recent call last):
 File "/home/fobu36/.virtualenvs/prova_selenium.py", line 16, in <module>
browser.find_element_by_link_text('Log in').click()
File "/home/fobu36/.local/lib/python3.6/site-
packages/selenium/webdriver/remote/webdriver.py", l
ine 317, in find_element_by_link_text
return self.find_element(by=By.LINK_TEXT, value=link_text)
File "/home/fobu36/.local/lib/python3.6/site-
packages/selenium/webdriver/remote/webdriver.py", l
ine 752, in find_element
'value': value})['value']
File "/home/fobu36/.local/lib/python3.6/site-
packages/selenium/webdriver/remote/webdriver.py", l
ine 236, in execute
self.error_handler.check_response(response)
File "/home/fobu36/.local/lib/python3.6/site-
packages/selenium/webdriver/remote/errorhandler.py"
, line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate 
element: {"method":"l
ink text","selector":"Log in"}
Stacktrace:
at FirefoxDriver.findElementInternal_ 
(file:///tmp/tmpbydkaxfk/extensions/fxdriver@googlecode.
com/components/driver-component.js:10770)
at fxdriver.Timer.setTimeout/<.notify 
(file:///tmp/tmpbydkaxfk/extensions/fxdriver@googlecode.
com/components/driver-component.js:625)

take a look at the webpage/response from instagram. maybe they are just blocking you.

So far, my code on my PC works. I can log in and do my stuff, and also instagram here its in the WhiteList Doing some attempts it seems that I can't even get the body of the page, seems like that instagram blocks my access if I run my app on pythonanywhere.com Do you think that it's possible?

that is possible, but you should still be able to see what the response that instagram sends back is. try to print it to see what they are saying.