httpclient库怎么在python3中使用

httpclient库怎么在python3中使用?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

如下所示:

httpclient库怎么在python3中使用

importhttp.client,urllib.parse
importhttp.client,urllib.parse
importrandom

USER_AGENTS=[
"Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.1;SV1;AcooBrowser;.NETCLR1.1.4322;.NETCLR2.0.50727)",
"Mozilla/4.0(compatible;MSIE7.0;WindowsNT6.0;AcooBrowser;SLCC1;.NETCLR2.0.50727;MediaCenterPC5.0;.NETCLR3.0.04506)",
"Mozilla/4.0(compatible;MSIE7.0;AOL9.5;AOLBuild4337.35;WindowsNT5.1;.NETCLR1.1.4322;.NETCLR2.0.50727)",
"Mozilla/5.0(Windows;U;MSIE9.0;WindowsNT9.0;en-US)",
"Mozilla/5.0(compatible;MSIE9.0;WindowsNT6.1;Win64;x64;Trident/5.0;.NETCLR3.5.30729;.NETCLR3.0.30729;.NETCLR2.0.50727;MediaCenterPC6.0)",
"Mozilla/5.0(compatible;MSIE8.0;WindowsNT6.0;Trident/4.0;WOW64;Trident/4.0;SLCC2;.NETCLR2.0.50727;.NETCLR3.5.30729;.NETCLR3.0.30729;.NETCLR1.0.3705;.NETCLR1.1.4322)",
"Mozilla/4.0(compatible;MSIE7.0b;WindowsNT5.2;.NETCLR1.1.4322;.NETCLR2.0.50727;InfoPath.2;.NETCLR3.0.04506.30)",
"Mozilla/5.0(Windows;U;WindowsNT5.1;zh-CN)AppleWebKit/523.15(KHTML,likeGecko,Safari/419.3)Arora/0.3(Change:287c9dfb30)",
"Mozilla/5.0(X11;U;Linux;en-US)AppleWebKit/527+(KHTML,likeGecko,Safari/419.3)Arora/0.6",
"Mozilla/5.0(Windows;U;WindowsNT5.1;en-US;rv:1.8.1.2pre)Gecko/20070215K-Ninja/2.1.1",
"Mozilla/5.0(Windows;U;WindowsNT5.1;zh-CN;rv:1.9)Gecko/20080705Firefox/3.0Kapiko/3.0",
"Mozilla/5.0(X11;Linuxi686;U;)Gecko/20070322Kazehakase/0.4.5",
"Mozilla/5.0(X11;U;Linuxi686;en-US;rv:1.9.0.8)GeckoFedora/1.9.0.8-1.fc10Kazehakase/0.5.6",
"Mozilla/5.0(WindowsNT6.1;WOW64)AppleWebKit/535.11(KHTML,likeGecko)Chrome/17.0.963.56Safari/535.11",
"Mozilla/5.0(Macintosh;IntelMacOSX10_7_3)AppleWebKit/535.20(KHTML,likeGecko)Chrome/19.0.1036.7Safari/535.20",
"Opera/9.80(Macintosh;IntelMacOSX10.6.8;U;fr)Presto/2.9.168Version/11.52",
'Mozilla/5.0(WindowsNT6.1;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/63.0.3239.132Safari/537.36'
]

defget_demo(num,keyword):
page=urllib.parse.urlencode({'page':num})
params=urllib.parse.urlencode({})

headers={'Referer':'http://t66y.com/index.php',
'User-Agent':random.choice(USER_AGENTS)
'Accept-Encoding':'gzip,deflate',
'Accept-Language':'zh-CN,zh;q=0.9',
}
conn=http.client.HTTPConnection("ttty.com",timeout=10)

conn.request("GET","/thread0806.php?fid=16&"+page,params,headers)

r1=conn.getresponse()

data=r1.read().decode('gbk')#Thiswillreturnentirecontent.
content=data.find(keyword)

ifcontent!=-1:
print('bingo:'+page)
else:
print('try{},status:{}'.format(page,r1.status))


defpost_demo():
params=urllib.parse.urlencode({'qruuid':'asdf','user_uuid':'3423412dfasf'})
headers={"Content-type":"application/x-www-form-urlencoded",
"Accept":"application/json"}
conn=http.client.HTTPSConnection("wx.coderr.cn")
conn.request("POST","/api/qrcode",params,headers)
response=conn.getresponse()
print(response.status,response.reason)

ifnotresponse.closed:
data=response.read()
print(data,type(data.decode('utf-8')))

conn.close()

if__name__=='__main__':
pass

关于httpclient库怎么在python3中使用问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注恰卡编程网行业资讯频道了解更多相关知识。

发布于 2021-03-26 01:50:02
收藏
分享
海报
0 条评论
160
上一篇:怎么在易语言中使用农历月历组件 下一篇:怎么在Python中使用正则匹配特定的字符
目录

    0 条评论

    本站已关闭游客评论,请登录或者注册后再评论吧~

    忘记密码?

    图形验证码