用python写爬取电影资源的代码
时间: 2024-05-26 19:10:17 浏览: 82
可以参考下面的代码片段:import requests
from bs4 import BeautifulSoupurl = 'https://www.example.com/movies/'
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')# 找到所有电影链接
movie_links = soup.find_all('a')for link in movie_links:
# 得到每个电影链接的文本
movie_name = link.text # 得到每个电影链接的地址
movie_url = link.get('href') # 进行爬取
movie_page = requests.get(movie_url)
movie_soup = BeautifulSoup(movie_page.text, 'html.parser') # 找到电影资源
movie_download_links = movie_soup.find_all('a')
for download_link in movie_download_links:
# 得到每个电影资源的文本
download_name = download_link.text # 得到每个电影资源的地址
download_url = download_link.get('href') # 打印电影名称和资源地址
print('电影名称: {}, 资源地址: {}'.format(movie_name, download_url))
阅读全文