使用bs4和requests爬取清华镜像源上面的包。
__SINN__:
#需要安装bs4和requests
from bs4 import BeautifulSoup
import requests as rq
pkg = input('>')
r = rq.get(f'https://pypi.tuna.tsinghua.edu.cn/simple/{pkg}')
soup = BeautifulSoup(r.text, 'html.parser')
r.close()
r2 = rq.get(soup.find_all('a')【-1】.get('href').replace('../..', 'https://pypi.tuna.tsinghua.edu.cn'))
#这里的路径要改一改。
with open(f'/sdcard/Python/test/{pkg}', 'wb') as f:
f.write(r2.content)
r2.close()
教程 Python BeautifulSoup requests