所以我正在尝试编写一个平庸的脚本来从一个特定的网站下载字幕,正如你们所看到的。我是 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'])
关于python - 美丽汤 : Fetched all the links on a webpage how to navigate through them without selenium?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49378038/