Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Login to web site
#1
Hello to everyone.

I'm starting to develop in Python. I need to make a script for automatic login to a certain website.

The site is: http://ec.gbgroup.it/orderentry/login.action

And i need to make a login and after this make a search in that website, getting the results.

I wrote a code for the automatic login, but it doesn't work, why? I'll post the code below.

Thanks for your help.

Best regards

Francesco

import time
import requests
from lxml import html
from bs4 import BeautifulSoup

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'}

payload = {'j_username': 'myusername', 'j_password': 'mypassword','submit': 'Login'}

login_url = "https://ec.gbgroup.it/orderentry/login.action"

with requests.Session() as session:

	#For testing purposes is removed the Certificate verification
	result = session.post(login_url, headers=headers, data=payload, verify=False)
	print(result.status_code)
	time.sleep(2)

	after_login_url = "https://ec.gbgroup.it/orderentry/home.action"
	result2 = session.get(after_login_url)
	print(result2.status_code)
	
	soup = BeautifulSoup(result.content, 'html.parser')
	soup2 = BeautifulSoup(result2.content, 'html.parser')

	filePtr = open( 'page.html', 'w' )
	filePtr.write( repr(soup) )
	filePtr.close()

	filePtr = open( 'page2.html', 'w' )
	filePtr.write( repr(soup2) )
	filePtr.close()
Reply
#2
The first thing I noticed is that you're sending the login request to the wrong url.
You should be sending it to https://ec.gbgroup.it/orderentry/j_security_check instead (the login form's action).

Also, the submit in your data isn't sent when logging in from the website, but language is.
This may or may not make a difference.
Reply
#3
Hi, thanks for your reply.

I tried changing the URL for the login, but the server gave me a 408 error (Timeout request).

I don't understand the issue related to the "submit" into the data.

Thanks for your time

Regards

Francesco

(Jan-02-2019, 10:17 AM)stranac Wrote: The first thing I noticed is that you're sending the login request to the wrong url.
You should be sending it to https://ec.gbgroup.it/orderentry/j_security_check instead (the login form's action).

Also, the submit in your data isn't sent when logging in from the website, but language is.
This may or may not make a difference.
Reply
#4
(Jan-02-2019, 01:11 PM)halo981 Wrote: I don't understand the issue related to the "submit" into the data.
Have to look what send as Form Data as mention bye @stranac.
submit is not send,but language is.
Try:
import time
import requests
from lxml import html
from bs4 import BeautifulSoup

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'}
params = {'j_username': 'myusername', 'j_password': 'mypassword', 'language': 'it'}
login_url = "https://ec.gbgroup.it/orderentry/login.action"
with requests.Session() as session:
    #For testing purposes is removed the Certificate verification
    result = session.post(login_url, headers=headers, params=params, verify=False)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020