gpt4 book ai didi

python - 美丽汤 : Fetched all the links on a webpage how to navigate through them without selenium?

转载 作者:太空宇宙 更新时间:2023-11-03 13:59:11 25 4
gpt4 key购买 nike

所以我正在尝试编写一个平庸的脚本来从一个特定的网站下载字幕,正如你们所看到的。我是 beautifulsoup 的新手,到目前为止,我有一个搜索查询(GET)后所有“href”的列表。那么,在获得所有链接后,如何进一步导航呢?代码如下:

import requests
from bs4 import BeautifulSoup

usearch = input("Movie Name? : ")
url = "https://www.yifysubtitles.com/search?q="+usearch
print(url)
resp = requests.get(url)
soup = BeautifulSoup(resp.content, 'lxml')
for link in soup.find_all('a'):
dictn = link.get('href')
print(dictn)

最佳答案

您需要使用resp.text而不是resp.content尝试此操作来获取搜索结果。

import requests
from bs4 import BeautifulSoup

base_url_f = "https://www.yifysubtitles.com"
search_url = base_url_f + "/search?q=last+jedi"
resp = requests.get(search_url)
soup = BeautifulSoup(resp.text, 'lxml')
for media in soup.find_all("div", {"class": "media-body"}):
print(base_url_f + media.find('a')['href'])

输出:https://www.yifysubtitles.com/movie-imdb/tt2527336

关于python - 美丽汤 : Fetched all the links on a webpage how to navigate through them without selenium?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49378038/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com