0

I need to login into the following website http://mediaweather.meteogroup.co.uk/ I attempted to do this using python with the following code but it doesn't appear to login any help would be appreciated :)

import urllib, urllib2, cookielib

username = ''
password = ''

cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
login_data = urllib.urlencode({'username' : username, 'password' : password})
opener.open('http://mediaweather.meteogroup.co.uk/login', login_data)
resp = opener.open('http://mediaweather.meteogroup.co.uk/observations/table/6040?country_id=6040&d=01&m=07&y=2016&h=11&i=00&sort=landstat_name_wmo&order=asc')
print resp.read()

1 Answers1

0

I would use requests to post the form data, the following shows you how:

# post url for logon
url = "http://mediaweather.meteogroup.co.uk/login/process"

data = {"txtusername": "username",
        "txtpassword": "pass"}

with requests.Session() as s:
        # login
        s.post(url, data=data)
        # get page you want
        html = s.get('http://mediaweather.meteogroup.co.uk/observations/table/6040?country_id=6040&d=01&m=07&y=2016&h=11&i=00&sort=landstat_name_wmo&order=asc).content
Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321