Created
August 10, 2018 16:59
-
-
Save nikhilkumarsingh/c354874a36c9d85f45fd14309e0afeff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup | |
headers = { | |
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36' | |
} | |
login_data = { | |
'name': '<username>', | |
'pass': '<password>', | |
'form_id': 'new_login_form', | |
'op': 'Login' | |
} | |
with requests.Session() as s: | |
url = 'https://www.codechef.com/' | |
r = s.get(url, headers=headers) | |
soup = BeautifulSoup(r.content, 'html5lib') | |
login_data['form_build_id'] = soup.find('input', attrs={'name': 'form_build_id'})['value'] | |
r = s.post(url, data=login_data, headers=headers) | |
print(r.content) |
@uddeshyy You better make use of cookies in the response . You can use status codes but Status codes are completely dependent on how the website responds. If the website giving 200 response code for both valid and invalid login then you can’t use. If Incase giving 400 for invalid and 200 for valid then there is change to use it as a key for success login.
@uminostech1089 you need to send the request the same way, the browser sending to the server. Use fidler or any http network debugging tools to read how the website is sending the requests to the server
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try this command in terminal: pip install html5ib