Answer the question
In order to leave comments, you need to log in
How to log in with requests in a PHP forum?
Hello.
I want to parse the demiart.ru forum to automate certain tasks. You need to be logged in to view topics. I have my username and password, of course. I'm trying to log in using this tutorial: https://kazuar.github.io/scraping-tutorial/
Actually, my code is taken from there with minimal changes:
import requests
from lxml import html
LOGIN_URL = "http://demiart.ru/forum/index.php?"
URL = "http://demiart.ru/forum/index.php?showtopic=8436"
session_requests = requests.session()
payload = {
"UserName": USERNAME,
"PassWord": PASSWORD,
"submit": 'Войти',
}
result = session_requests.post(LOGIN_URL, data=payload, headers=dict(referer=LOGIN_URL))
result = session_requests.get(URL, headers=dict(referer=URL))
tree = html.fromstring(result.content)
theme_title = tree.xpath(".//div[@class='f_break tablefixed']")
print(theme_title)
<Element html at 0x3b3a188>
). Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question