python,使用代理模式访问淘宝,百度,京东,阿里
2018-03-23 00:00
711 查看
#!/usr/bin/env python # -*- coding:utf-8 -*- import requests import json import urllib def get(url,datas=None,headers={}): response = requests.get(url, params=datas,headers=headers) json_rsp = response.json() return json_rsp #传递 json 数据 post 请求的专用方法 def post_json(url,datas=None,headers=None): json_dumps= json.dumps(datas) response = requests.post(url, data=json_dumps,headers=headers) json_rsp = response.json() return json_rsp def post_urlencoded(url,datas=None,headers=None): body_value = urllib.parse.urlencode(datas) response = requests.post(url, data=body_value,headers=headers) json_rsp = response.json() return json_rsp def post(url,datas=None,headers=None): response = requests.post(url, data=datas,headers=headers) json_rsp = response.json() return json_rsp def get_form(url,datas=None,headers={}): response = requests.get(url, data=datas,headers=headers) json_rsp = response.json() return json_rsp #get方法测试代理 def test(url1,url2): resp=get_form(url1);#调用接口返回连接池可用代理 proxy=resp["data"]["data"][0]["ip"]+":"+resp["data"]["data"][0]["port"]#使用接口返回的第一个代理ip+端口号 proxies = {"https": proxy, }#设置代理参数 # proxies = {"https": "192.168.1.1:8080", } for i in range(len(url2)): resp=requests.get(url2[i],proxies=proxies)#代理模式调用淘宝,京东,百度 print resp if(str(resp)=="<Response [200]>"):#判断返回响应情况 print "sucess"; else: print "error"; url1="http://192.168.33.76:25588/ip/available?flag=taobao&count=1"; # url2= ["https://www.jd.com", "https://www.taobao.com", "https://www.baidu.com"]; url2= ["https://www.baidu.com"] test(url1,url2);
相关文章推荐
- 一个简单的使用代理访问百度页面内容的python脚本
- python3使用代理ip访问指定网站
- python3使用多代理访问网站
- python使用代理访问网站
- python使用代理ip访问网站
- python使用代理ip访问网站的实例
- python3使用多代理访问网站
- python3 使用代理访问
- python使用代理访问服务器
- Python3中使用代理访问网页
- python3使用多代理访问网站
- python使用代理访问服务器
- Nginx反向代理使用IIS,使其可以同时在同一端口上访问ASP.NET MVC和Python
- python 使用代理访问网站
- python基础===文件对象的访问模式,以及计数循环的使用方法
- python3使用多代理访问网站
- 使用Python2.4在Linux下访问SQL Server(安装篇)
- java使用代理访问网络的几种方法
- PHP 初学者 使用cURL并用代理访问http
- 使用python访问hbase