python 登录知乎 一直是10030错误 但是网页端可以正常登录 是否是因为IP被知乎封了?
澳门新葡京官网
澳门新葡京官网
当前位置 : 澳门新葡京官网 > 澳门新葡京官网

python 登录知乎 一直是10030错误 但是网页端可以正常登录 是否是因为IP被知乎封了?

问题同上


from urllib import request,parse
import urllib,io,json,time,gzip,http
import re
import requests
# 设置cookie
cookie = http.cookiejar.CookieJar
cookieProc = urllib.request.HTTPCookieProcessorcookie
opener = urllib.request.build_openercookieProc
urllib.request.install_openeropener

# 获取xsrf token
hh = urllib.request.urlopenhttps://www.zhihu.com
h = hh.read.decode"utf8"
patten = re.compilername="_xsrf" value=".*?"
b = patten.searchh
# 获取captcha
time = strinttime.time*1000
captchaUrl = https://www.zhihu.com/captcha.gif?r=+ time +&type=login
req = request.RequestcaptchaUrl
with request.urlopenreq as w:
    print"Status: %s %s" %w.status,w.reason
    o = opend:/captcha.gif,wb
    o.writew.read
    o.close
    printw.getheaders
captcha = input请输入captcha
headers = {
    Host: www.zhihu.com,
    Connection: keep-alive,
    Accept: */*,
    Accept-Encoding: gzip,deflate,
    Accept-Language: zh-CN,zh;q=0.8,
    Origin: http://www.zhihu.com,
    X-Requested-With: XMLHttpRequest,
    Referer:http://www.zhihu.com/,
    Content-Type:application/x-www-form-urlencoded; charset=UTF-8,
    User-Agent:Mozilla/5.0 Windows NT 6.1 AppleWebKit/537.36 KHTML, like Gecko Chrome/45.0.2454.85 Safari/537.36,
    Content-Length:98
}
postData = {
        username: xxxxx@gmail.com,
         password: xxxxx,
         _xsrf:b.group1,
         captcha:captcha
}

printpostData[_xsrf]
# login
postData =data = urllib.parse.urlencodepostData.encodeencoding=UTF8
request1 = urllib.request.Requesthttp://www.zhihu.com/login/email ,postData,headers
response = opener.openrequest1
printresponse.getheaders
bi = io.BytesIOresponse.read
gziper = gzip.GzipFilefileobj=bi, mode="rb"
data2 = gziper.read
printjson.loadsdata2.decodeutf-8

不是吧,要是IP被封了,网页也会打不开的。

import requests, pyquery, urllib

url = https://www.zhihu.com
info_url = {0}/#signin.formaturl
login_url = {0}/login/phone_num.formaturl

session = requests.Session
session.headers = {
    Accept-Language: zh-CN,zh;q=0.8,en;q=0.6,
    Content-Type: application/x-www-form-urlencoded; charset=UTF-8
}
Q = pyquery.PyQuerysession.getinfo_url.text

data = {
    _xsrf: Qinput[name="_xsrf"].val,
    phone_num: 13311111111,
    password: 111
}

r = session.postlogin_url, data=urllib.urlencodedata
print r.text

栏目列表

广告位

澳门新葡京官网