2

So I am trying to login programatically (python) to https://www.datacamp.com/users/sign_in using my email & password.

I have tried 2 methods of login. One using requests library & another using selenium (code below). Both time facing [403] issue.

Could someone please help me login programatically to it ?

Thank you !

Using Requests library.

import requests; r = requests.get("https://www.datacamp.com/users/sign_in"); r (which gives <response [403]>)

Using Selenium webdriver.

 driver = webdriver.Chrome(executable_path=driver_path, options=option)
 driver.get("https://www.datacamp.com/users/sign_in")
 driver.find_element_by_id("user_email") # there is supposed to be form element with id=user_email for inputting email
zen
  • 21
  • 1

2 Answers2

1

Implicit wait at least should have worked, like this:

from selenium import webdriver


driver = webdriver.Chrome(executable_path='/snap/bin/chromium.chromedriver')
driver.implicitly_wait(10)
url = "https://www.datacamp.com/users/sign_in"
driver.get(url)
driver.find_element_by_id("user_email").send_keys("test@dsfdfs.com")
driver.find_element_by_css_selector("#new_user>button[type=button]").click()

BUT

The real issue is the the site uses anti-scraping software. If you open Console and go to request itself you'll see: enter image description here

It means that the site blocks your connection even before you try to login. Here is similar question with different solutions: Can a website detect when you are using Selenium with chromedriver?

Not all answers will work for you, try different approaches suggested.

With Firefox you'll have the same issue (I've already checked).

vitaliis
  • 4,082
  • 5
  • 18
  • 40
  • Thank you ! I understand the issue now. Is it also the case that the website is blocking the login using requests library ? It seems so. Is there a way to work around it ? – zen Apr 30 '21 at 12:28
  • I added the issue with multiple suggestions on how it can be fixed. Frankly, it is not an easy task, I'd start from the easiest one https://stackoverflow.com/a/62520191/12730112 and then would try the approved answer. But do not forget to make a backup of your chromedriver before trying it. – vitaliis Apr 30 '21 at 12:33
0

You have to add a wait after driver.get("https://www.datacamp.com/users/sign_in") before driver.find_element_by_id("user_email") to let the page loaded.
Try something like WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'user_email')))

Prophet
  • 32,350
  • 22
  • 54
  • 79
  • Thats not the issue. I forgot to add wait in the code snippet I shared here, but original code had it. Not able to login even with requests library. – zen Apr 30 '21 at 10:58