加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
search.py 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
福叔攒钱买房车 提交于 2021-12-04 17:49 . 添加了采集器。
# 搜索Ubuntu包
import requests
from bs4 import BeautifulSoup
from tables import *
pkgUrl = "https://mirrors.163.com/ubuntu/pool/main/"
def searchPackage(url,pkgName):
r = requests.get(url)
soup = BeautifulSoup(r.content,"lxml")
alist = soup.findAll("a")
for aitem in alist:
href = aitem.get("href")
if "../" != href:
full_url = url + href
if not isFileUrl(full_url):
searchPackage(full_url,pkgName)
else:
if href.startswith(pkgName):
print(full_url)
def celloctPackage(url):
r = requests.get(url)
soup = BeautifulSoup(r.content,"lxml")
alist = soup.findAll("a")
for aitem in alist:
href = aitem.get("href")
if "../" != href:
full_url = url + href
if not isFileUrl(full_url):
celloctPackage(full_url)
else:
with session_scope() as se:
pkgs = PkgsTable()
pkgs.pkgName = href
pkgs.pkgUrl = full_url
se.add(pkgs)
def isFileUrl(url):
if url.endswith(".deb"):
return True
return False
if __name__ == '__main__':
celloctPackage(pkgUrl)
# searchPackage(pkgUrl,"libarchive13")
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化