login - python post data with requests in python -
if try login account , not successful have phrase try again
in url source page. tried write python script login account , stuff:
update
token=...#by xpath session=requests.session('http://example.com') response=session.get('http://example.com') cook=session.cookies postdata={'token':token, 'arg1':'', 'arg2':'', 'name[user]': user, 'name[password]':password, 'arg3': 'sign in'} postresp=requests.post(url='http://example.com/sth', cookies=cook, data=post_data) print postresp.content
is there wrong postdata or etc?
i sat cookies.
you don't want show url - , difficult hit bulls eye without it:-)
here's try let me know if works or please comment error here after.
please note following points: -try use user agent in headers -token needs fetched after calling url (in following case 5th line)
session=requests.session() headers={"user-agent":"mozilla/5.0 (x11; linux i686) applewebkit/537.36 (khtml, gecko) chrome/36.0.1985.125 safari/537.36"} session.headers.update(headers) response=session.get('http://example.com').content #i added line tree=html.fromstring(cont) #and line token=tree.xpath('//*[@class="blah blah blah"]') #cook=session.cookies -- don't need if continuing same session postdata={'token':token, 'arg1':'', 'arg2':'', 'name[user]': user, 'name[password]':password, 'arg3': 'sign in'} postresp=session.post(url='http://example.com/sth', data=post_data) # use session.post instead of making new request print postresp.content
also, please check if there specific content-type
if yes, please add headers
hope helps :-)
Comments
Post a Comment