码迷,mamicode.com
首页 > 编程语言 > 详细

python+fastapi自建HTTP爬虫IP池接口

时间:2020-12-02 12:09:56      阅读:6      评论:0      收藏:0      [点我收藏+]

标签:return   直接   ges   head   -o   http代理   pre   beautiful   很多   

使用的库

  • bs4
  • requests
  • pymongo
  • fastapi
  • uvicorn

爬取ip

网络上搜索一下有很多提供HTTP代理的网站,直接使用BeautifulSoup将IP爬下来。

html =requests.get(url).text
bs =BeautifulSoup(html,‘html.perser‘)
#findAll()
#select()

验证ip

res = requests.get(url,headers=headers,proxies=proxies)
#判断res.status_code是否等于200
#db.insert_one()

如果验证成功写入数据库。

接口

使用fastapi

@app.get(‘/api‘)
def api():
	data = 查询数据库随机返回一条
	return data

效果展示

技术图片
技术图片

演示地址:找IP

python+fastapi自建HTTP爬虫IP池接口

标签:return   直接   ges   head   -o   http代理   pre   beautiful   很多   

原文地址:https://www.cnblogs.com/aosky/p/14048149.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!