首页 > 解决方案 > 我将如何使用 python3 在网站中查找特定链接

问题描述

我正在尝试构建一个抓取该网站的 python 程序:(https://fitgirl-repacks.site/dungeon-defenders-awakened/),然后只返回 1337x 下载链接:(https://1337x.to /torrent/4474599/Dungeon-Defenders-Awakened-v1-0-0-17001-MULTi8-FitGirl-Repack/)。我成功抓取了网站,但是我将如何编写找到 1337x 下载链接的程序:(https://1337x.to/torrent/4474599/Dungeon-Defenders-Awakened-v1-0-0-17001 -MULTi8-FitGirl-Repack/ ),并在 python 控制台中返回它?

标签: pythonweb-scraping

解决方案


使用 BeautifulSoup 您可以提取网址:

from requests import get
from bs4 import BeautifulSoup

response = get('https://fitgirl-repacks.site/dungeon-defenders-awakened/')
html_text = response.text
html = BeautifulSoup(html_text)

tags = html.find_all("a", string="1337x")
first_tag = tags[0]
print(first_tag['href'])

推荐阅读