所以我试图编写一个平庸的脚本来从一个特定的网站下载字幕,因为所有人都可以看到。我是beautifulsoup的新手,到目前为止,我已经列出了所有" href"在搜索查询(GET)之后。在获得所有链接后,如何进一步导航? 这是代码:
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)
答案 0 :(得分:1)
您需要使用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'])