I have been trying to automate login into stackoverflow to learn web scrapping. First I tried scrapy, from which I did not get that lucky using following code.
im
In addition to the way by Wim Hermans, you can also POST https://stackoverflow.com/users/login with the following parameters:
email: your emailpassword: your passwordfkeyHere's an example:
import requests
import getpass
from pyquery import PyQuery
# Fetch the fkey
login_page = requests.get('https://stackoverflow.com/users/login').text
pq = PyQuery(login_page)
fkey = pq('input[name="fkey"]').val()
# Prompt for email and password
email = input("Email: ")
password = getpass.getpass()
# Login
requests.post(
'https://stackoverflow.com/users/login',
data = {
'email': email,
'password': password,
'fkey': fkey
})
from scrapy import FormRequest
url = "https://stackoverflow.com/users/login"
fetch(url)
req = FormRequest.from_response(
response,
formid='login-form',
formdata={'email': 'test@test.com',
'password': 'testpw'},
clickdata={'id': 'submit-button'},
)
fetch(req)