0

I have just started with some web-scraping. Unfortunately, I am trying to access http://.classic.comunio.de with the following code

self.session = requests.session()
payload = {'login': self.username ,
           'pass': self.password,
           'action': 'login'}

headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain",
               "User-Agent": user_agent}

req = self.session.post('http://'+self.domain+'/login.phtml',headers=headers,data=payload).content

I have checked http://classic.comunio.de about the names of username, password and action. That should be right. Username and password are also correct.

However, when I try to login and I am not forwarded to the next page or I can not get the content of my user profile, which should be possible after logging in.

All help is appreciated, thank you!

Felix
  • 11
  • 2
  • Did you have a look at this post first? [link](https://stackoverflow.com/questions/11892729/how-to-log-in-to-a-website-using-pythons-requests-module) – blacktj Jul 22 '19 at 19:17

1 Answers1

0

Try using a header , the page probably finds your script as a bot and blocks it.The following code worked fine for me:

import requests
from bs4 import BeautifulSoup

url='https://classic.comunio.de/login.phtml'
header={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
payload={'login':'yourname','pass':'yourpass'}

s=requests.Session()
page = s.post(url,data=payload,headers=header)
soup = BeautifulSoup(page.content,'html.parser')
result = soup.find('div',attrs={'id':"manager"}).get_text()
print(result)
johnsnow06
  • 111
  • 7