Jan-02-2019, 07:44 AM
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
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()