码迷,mamicode.com
首页 > 编程语言 > 详细

Python requets 登录51cto家园

时间:2016-05-09 21:59:20      阅读:508      评论:0      收藏:0      [点我收藏+]

标签:

#-coding:utf-8 -*-

import requests
import urllib
from bs4 import BeautifulSoup

HEADERS={
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36",
    "Content-Type": "application/x-www-form-urlencoded",
}

URL="http://home.51cto.com/index"

params={
    "reback":"http://www.51cto.com/",
    "_csrf":None,
    "LoginForm[username]":"账号",
    "LoginForm[password]": "密码",
    "LoginForm[rememberMe]":0,
    "login-button":"登 录"
}

client = requests.Session()
resp = client.get(URL)
soup = BeautifulSoup(resp.content, "html.parser")
csrf = soup.find(attrs={"name":"csrf-token"})[content]
params["_csrf"] = csrf
params = urllib.urlencode(params)

resp = client.post(URL, data=params, headers=HEADERS)
#print resp.content
#soup = BeautifulSoup(resp.content, "html.parser")
#for src in soup.find_all("script"):
#    client.get(src.get("src"))
resp = client.get(URL)
print resp.content

 

Python requets 登录51cto家园

标签:

原文地址:http://www.cnblogs.com/jachin/p/5475502.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!