Python -- i'm try print an element from site with authorization but it doest'n work - why?

Please help me, I tried to print an element from site with authorization, but it doesn't work, because block with authorization doesn't perform its functions and instead of "Hello -username-" output "u don't registered" my code:

import requests
from bs4 import BeautifulSoup as BS
import fake_useragent

session = requests.Session()
url = "http://www.musicforums.ru/buysell/login.php?bn=mfor_buysell"

user = fake_useragent.UserAgent().random
header = {
    'user-agent':user
}
data = {
    'loginuser':'moscow_sunset',
    'loginpassword':'PfEQg4'
}
responce = session.post(url, data=data, headers=header).text



link = "http://www.musicforums.ru/"

page = requests.get(link)
soup = BS(page.content, 'html.parser')
name = soup.find_all('div', {'class': "block-reg"})[0]
find_td = name.find('td', {'align':"center"}).text
t = find_td.encode('ISO-8859-1').decode('Windows-1251')
print(t)

P.S. before that there was a problem with encoding(answer output like unreadable symbols) but I solved it

The problem here is with

page = requests.get(link)

You are requesting this page as if you had never logged in. You need to parse responce for the key that the login request returned. Then you need to include the correct headers to tell the server that you are actually logged in.

Back to Top