无法使用Python发布数据

时间:2015-07-18 10:01:33

标签: python login http-post

这是我到目前为止所拥有的。我正在尝试登录并查看成员页面,但我似乎无法实现这一目标。非常感谢任何帮助!

import requests 

s = requests.Session()
url = 'http://theocarinanetwork.com/login'                    
uname = 'USERNAME'                                                               
pw = 'PASSWORD'  
headers = {'User-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
           'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
           'Accept-Encoding': 'gzip,deflate,sdch',                  
           'Accept-Language': 'en-US,en;q=0.8',                     
           'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'}

data = {'uname':uname,                                                          
        'pw':pw,                                                        
        'submit':'button',                                          
        'base_uri':'http://theocarinanetwork.com/index'} 
response = s.post(url, headers = headers)

if response.status_code == 200: 
response = s.get('http://theocarinanetwork.com/members/')

print response.text

1 个答案:

答案 0 :(得分:0)

import requests 

s = requests.Session()
url = 'http://theocarinanetwork.com/login/log_in'                    
uname = '******'                                                               
pw = '******'  
headers = {'User-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
       'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
       'Accept-Encoding': 'gzip,deflate,sdch',                  
       'Accept-Language': 'en-US,en;q=0.8',                     
       'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'}
data = {'uname':uname,                                                          
    'pw':pw,                                                        
    'submit':'button',                                          
    'base_uri':'http://theocarinanetwork.com/index'}

response = s.post(url, data, headers = headers)

if response.status_code == 200: 
    response = s.get('http://theocarinanetwork.com/members/')
    print response.text