python+fastapi自建HTTP爬虫IP池接口
使用的库
- 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
版权声明:本文为aosky原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。