注册
登录
 文档中心 产品介绍 开发指南 API接口 代码样例 使用帮助
文档中心 / 代码样例 / Python-feapder /
Python使用feapder调用Http代理IP的代码样例
站大爷 官方 2024-01-20 1542 浏览

温馨提示:

1.  http/https 网页均可适用

2.  运行环境要求 python3.6 以上

3.  使用命令 feapder create -s py3_feapder 创建一个轻量爬虫

4.  feapder 不是 python 原生库,需要安装才能使用: pip install feapder

5.  注意替换代码中的部分信息:username:用户名,password:密码

6.  代码样例中的代理IP和端口均为虚构,请通过站大爷的API提取链接获取代理IP后使用,避免报错


import feapder


class Py3Feapder(feapder.AirSpider):
	def start_requests(self):
		yield feapder.Request("https://example.com")

	def download_midware(self, request):
		# 提取代理API接口,获取1个代理IP
		api_url = "http://www.***.com/ShortProxy/GetIP/?api=1234567890&akey=8a17ca305f683620&count=10&timespan=3&type=3"

		# 获取API接口返回的代理IP
		proxy_ip = feapder.Request(api_url).get_response().text

		# 用户名密码授权
		username = "username"
		password = "password"
		proxies={
			"http":"http://username:password@168.168.168.168:12345,"
			"https":"http://username:password@168.168.168.168:12345"
		}

		#白名单方式(需提前绑定终端IP)
		#proxies={
			#"http":"http://168.168.168.168:12345",
			#"https":"http://168.168.168.168:12345"
		#}
		request.proxies = proxies
		return request

	def parse(self, request, response):
		print(response.text)


if __name__ == "__main__":
	Py3Feapder().start()


立即注册站大爷用户,免费试用全部产品
立即注册站大爷用户,免费试用全部产品