Skip to content

Commit

Permalink
Merge pull request xchaoinfo#62 from helmz/master
Browse files Browse the repository at this point in the history
fix weibo.cn login
  • Loading branch information
xchaoinfo committed Mar 31, 2017
2 parents d5a4d6f + 32c9e09 commit c61666b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions 003 weibo.cn/weibo.cn.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@

headers = {
"User-Agent": agent,
"Host": "login.weibo.cn",
"Host": "weibo.cn",
"Origin": "https://login.weibo.cn",
"Referer": "https://login.weibo.cn/login/"
}

session = requests.session()

url_login = 'https://login.weibo.cn/login/'
url_login = 'https://weibo.cn/login/'


def get_params(url_login):
html = session.get(url_login, headers=headers)
# print(html.text)
pattern = r'action="(.*?)".*?type="password" name="(.*?)".*?name="vk" value="(.*?)".*?name="capId" value="(.*?)"'
pattern = r'action="(*?)".*?type="password" name="(.*?)".*?name="vk"\
value="(.*?)".*?name="capId" value="(.*?)"'
res = re.findall(pattern, html.text, re.S)
# print(res)
return res
Expand All @@ -54,12 +55,11 @@ def get_cha(capId):
im.close()
except:
print("请到当前目下去找cha.jpg 输入验证码")
cha_code = input("请输入验证码")
cha_code = input("请输入验证码:")

return cha_code



res = get_params(url_login)
if res == []:
print("你的网络有问题,请检查网络后重试")
Expand All @@ -69,24 +69,25 @@ def get_cha(capId):

if __name__ == "__main__":
cha_code = get_cha(capId)
email = input("请输入你的邮箱账号或者手机号码")
password_input = input("请输入你的密码")
email = input("请输入你的邮箱账号或者手机号码:")
password_input = input("请输入你的密码:")
postdata = {
"mobile": email,
"code": cha_code,
"remember": "on",
"backURL": "http%3A%2F%2Fweibo.cn",
"backTitle": "手机新浪网",
"backTitle": "微博",
"tryCount": "",
"vk": vk,
"capId": capId,
"submit": "登录",
}
# print(postdata)
postdata[password] = password_input
post_url = url_login + post_url
# print(post_url)
page = session.post(post_url, data=postdata, headers=headers)
index = session.get("http://weibo.cn")
print(index.text)



# cookies = requests.utils.dict_from_cookiejar(session.cookies)
# print(cookies)

0 comments on commit c61666b

Please sign in to comment.