今天给你们带来了使用 mechanicalsoup 爬取电影天堂(https://www.dytt.to)中电影名,电影,以及磁力链接的实例
import mechanicalsoup
from urllib.parse import urljoin, unquote
#创建Browser对象
browser = mechanicalsoup.Browser()
#访问电影天堂欧美电影
url = "https://www.dytt.to/html/gndy/oumei/"
page = browser.get(url)
#获取电影名
links = page.soup.select(".ulink")
for link in links:
text = link.text.strip()
#获取链接
href = link.get("href")
full_url = urljoin(url, href)
#访问电影链接
movie_page = browser.get(full_url)
#获取<div id="Zoom">标签
zoom_div = movie_page.soup.find("div", {"id": "Zoom"})
#如果zoom_div存在,则获取<a>标签的href值
if zoom_div:
a_tags = zoom_div.find_all("a")
for a_tag in a_tags:
a_href = unquote(a_tag.get("href"))
print(f"电影名:{text}\n链接:{full_url}")
print(f"磁力下载链接:{a_href}\n\n")
print("-----------------")
输出:
电影名:2023 年剧情惊悚《沼泽王的女儿》BD 中英双字
链接:https://www.dytt.to/html/gndy/dyzz/20231123/64365.html
磁力下载链接:magnet:?xt=urn:btih&dn = 阳光电影 dygod.org. 沼泽王的女儿.2023.BD.1080P. 中英双字.mkv&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://exodus.desync.com:6969/announce
电影名:2023 年动画喜剧《蜥蜴伯伯里奥》BD 中英双字
链接:https://www.dytt.to/html/gndy/dyzz/20231123/64363.html
磁力下载链接:magnet:?xt=urn:btih:699620e20227fcebbbaac4f6a76988ee59354cc1&dn = 阳光电影 dygod.org. 蜥蜴伯伯里奥.2023.BD.1080P. 中英双字.mkv&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://exodus.desync.com:6969/announce
电影名:2023 年动作《约翰尼与克莱德》BD 英语中字
链接:https://www.dytt.to/html/gndy/jddy/20231122/64362.html
磁力下载链接:magnet:?xt=urn:btih:61b765ce57d2aaa58fccc8ff2b42da9445618a81&dn = 阳光电影 dygod.org. 约翰尼与克莱德.2023.BD.1080P. 英语中字.mkv&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://exodus.desync.com:6969/announce
电影名:2023 年剧情《盲证》BD 中英双字
链接:https://www.dytt.to/html/gndy/jddy/20231121/64359.html
磁力下载链接:magnet:?xt=urn:btih:625c90c6d1b218a338c03ec4b3fea01c3f9fde9a&dn = 阳光电影 dygod.org. 盲证.2023.BD.1080P. 中英 双字.mkv&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://exodus.desync.com:6969/announce
电影名:2023 年恐怖《驱魔人:信徒》BD 英语中字
链接:https://www.dytt.to/html/gndy/jddy/20231120/64357.html
磁力下载链接:magnet:?xt=urn:btih&dn = 阳光电影 dygod.org. 驱魔人:信徒.2023.BD.1080P. 英语中字.mkv&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://exodus.desync.com:6969/announce
电影名:2023 年剧情惊悚《男气管制》BD 中英双字
链接:https://www.dytt.to/html/gndy/jddy/20231119/64356.html
磁力下载链接:magnet:?xt=urn:btih:94c703906554074e3e90f9d36d839a75f3845209&dn = 阳光电影 dygod.org. 男气管制.2023.BD.1080P. 中英双字.mkv&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://exodus.desync.com:6969/announce
电影名:2023 年剧情惊悚《男气管制》BD 中英双字
链接:https://www.dytt.to/html/gndy/jddy/20231119/64356.html
磁力下载链接:magnet:?xt=urn:btih:94c703906554074e3e90f9d36d839a75f3845209&dn = 阳光电影 dygod.org. 男气管制.2023.BD.1080P. 中英双字.mkv&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://exodus.desync.com:6969/announce
电影名:2023 年剧情惊悚《男气管制》BD 中英双字
链接:https://www.dytt.to/html/gndy/jddy/20231119/64356.html
磁力下载链接:magnet:?xt=urn:btih:94c703906554074e3e90f9d36d839a75f3845209&dn = 阳光电影 dygod.org. 男气管制.2023.BD.1080P. 中英双字.mkv&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://exodus.desync.com:6969/announce