使用playwright爬取头条热榜,使用mechanicalsoup开发超级好用的磁力搜索工具(附完整源码)

使用playwright爬取头条热榜,使用mechanicalsoup开发超级好用的磁力搜索工具(附完整源码)。

使用playwright爬取头条热榜,使用mechanicalsoup开发超级好用的磁力搜索工具(附完整源码)_第1张图片

使用playwright爬取头条热榜,使用mechanicalsoup开发超级好用的磁力搜索工具(附完整源码)_第2张图片

安装playwright:

pip install playwright beautifulsoup4

完整实例:


from playwright.sync_api import Playwright, sync_playwright
from bs4 import BeautifulSoup
with sync_playwright() as playwright:
    browser = playwright.chromium.launch(headless=True)
    context = browser.new_context(extra_http_headers={"User-Agent": "Mozilla/5.0"})
    page = context.new_page()
    url = "https://www.toutiao.com/"
    page.goto(url)
    #等待热点板块元素加载完成
    page.wait_for_selector('.ttp-hot-board')
    html_content = page.content()
    soup = BeautifulSoup(html_content, 'html.parser')
    hot_board = soup.select_one('.ttp-hot-board')
    links = hot_board.find_all('a')
    for link in links:
        href = link['href']
        text = link.text
        print(text,href)

    #关闭浏览器
    browser.close()

输出: xxxxxxxx
https://www.toutiao.com/article/7310152393302409780/
1回应男子将女子幼儿拖出车外
https://www.toutiao.com/trending/7309812632712642594/?rank=1
2武大教授被前妻实名举报赌博
https://www.toutiao.com/trending/7310108006682329122/?rank=2
3中欧经贸合作成果丰硕 https://www.toutiao.com/article/7310141548892095010
4司机高速上睡着致翻车被甩出车外
https://www.toutiao.com/trending/7309750366102290469/?rank=4
5解克锋:不管买家是谁我都恨他
https://www.toutiao.com/trending/7310084622414282771/?rank=5
6女儿跑步暴瘦几十斤 父亲全程陪伴
https://www.toutiao.com/trending/7310037261054115903/?rank=6
7将在2024年竞
https://www.toutiao.com/trending/7310181078554119699/?rank=7
8xxxxxxxx试制度
https://www.toutiao.com/trending/7310082913393967167/?rank=8
9金丝猴爸爸带娃像极了人类
https://www.toutiao.com/trending/7309426866056921123/?rank=9


基于BT世界网(https://www.btsj6.com/)搜索功能爬取实现的。仅供学习!

安装mechanicalsoup:

pip install mechanicalsoup

完整实例:

import mechanicalsoup
import urllib.parse
def get_magnet_links(search_term):
    browser = mechanicalsoup.StatefulBrowser()
    url = f"https://www.btsj6.com/?s={search_term}"
    browser.open(url)
    magnet_links = []
    results = browser.get_current_page().select('.postli-1 a')
    for result in results:
        text = result.text 
        browser.follow_link(result)
        new_page = browser.get_url()
        download_links = browser.get_current_page().select('#zdownload a')
        for download_link in download_links:
            magnet = {
                'BaseName': text,
                'name': download_link.text,
                'link': urllib.parse.unquote(download_link['href'])  # 解码URL编码
            }
            magnet_links.append(magnet)
    browser.close()
    return magnet_links
search_term = "漫威" #关键词
magnet_links = get_magnet_links(search_term)
#输出磁力链接
for link in magnet_links:
    print(f"电影名: {link['BaseName']} \n 磁力名称: {link['name']}\n 磁力: {link['link']}\n ****************\n")

输出:
电影名: 银河护卫队:假日特辑-HD1080P-MP4-中文字幕 磁力名称:
1080P种子银河护卫队:假日特辑-HD1080P-MP4-中文字幕-2.26GB.torrent 下载页面 磁力:
https://www.btsj6.com/down.php?4d374f9/jC5zodoLFXRio8GHsruFtuQoVo4MbBbHcM+glM0g6nkFO1dnkQUBPPylhfHQ902PYJ8dE5eA32NEDHDhtJzB0KQM39CkHc3cvWKYFZBFKDbFrjaeOV0WvP/Nl/l74+m3LmRqJlPwpe4IbKbmHMMApSSjmkFOvEWyGlTmmZUGEM1z1RL5242l73HeEzn+4ZnSG2DDNOLMmV7KFH3ga0uR4lI0BNFj+0KbE5MOdG7kal9FMTb9fg


电影名: 乐高复仇者联盟:红色代码-HD1080P-MP4-中文字幕 磁力名称:
1080P种子乐高复仇者联盟:红色代码-HD1080P-MP4-中文字幕-1.87GB.torrent 下载页面 磁力:
https://www.btsj6.com/down.php?b36aGuejSX4hoONWN9F216vBDNAbvexJy8Y4i2etB0N7UxAIKfAWkQs1E0TPZTsjRFWUevrGvzuMS4ZaTkXgEu0aWk8SfhbF3NP34jJ1VDtpzcuE09SndmrxS8XhAEy3VzKPRRvDVFGgm9UjYv3f7JAb0KjJZhfwgYPyLU9C+PA7hHQLD/7Y+IMKzpP/ZkW9c37SDpZB7f9LwbTOoHZgAzc4INS5zC15o1wga+BNmQR3FBrMRGKqXd5RcGU/LLpxE8MckdGvkA


电影名: 斯坦·李-HD1080P-MP4-中文字幕 磁力名称:
1080P种子斯坦·李-HD1080P-MP4-中文字幕-2.56GB.torrent 下载页面 磁力:
https://www.btsj6.com/down.php?55d2itYX3p0RxanCodEBDB+Z+FxPP7vHD20w575ta5Ms3e7QXU0o9k2DNDUtYwys3bTDCLjqNFFil9b0kz8b3d3NNESMieclsFENctTXmcJP5e5jMltAJYUi21++B4s9t98iEOdWslxKCbfikO28/e0PQzuTHRysJRMGuSh+V/CbybDSaMJexG+cV1W2BFK67TNctkM


电影名: 蚁人与黄蜂女:量子狂潮-BD1080P/2160P-MP4-中文字幕 磁力名称:
1080P种子蚁人与黄蜂女:量子狂潮-BD1080P-MP4-中文字幕-3.27GB.torrent 下载页面 磁力:
https://www.btsj6.com/down.php?c68ehWLjtPUzNcWVcbp6ZVDporJtXh74w9fxrQ03p8gaxuwwoQr5lHYRARU09ScbZVy1u1mun9qDxWIhgAi9KvC2TELCou3c4l/1D+bCekibZU1cBca5ZFRQa0o2XHXGBN4b0tewaAawjb500POat/XBZ/aoJ3vggsqyPr9gYI5RIz3C1KP8bKuZGCLPo1N7duomaZBUE0C0gGBFZcnWXJgQb0p58MEWl/cx2FsoYN9fZq5WGdCpGJKJ52g+RgY


电影名: 蚁人与黄蜂女:量子狂潮-BD1080P/2160P-MP4-中文字幕 磁力名称:
4K种子蚁人与黄蜂女:量子狂潮-HD2160P-MP4-中文字幕-4.63GB.torrent 下载页面 磁力:
https://www.btsj6.com/down.php?6506HoC80YW6gT0aaSu3pKia71QNx0NrxDAHcdHOAfH5mZ9u7IXmr6+K9NCWzGMH68Vhch6TKZacBXWRzGNTiWqGqS0NMYHzTUN3pV/6ajS7cKT36+VpSUPdLYBH0yUyP/SfOrWgdOLwHspO1qTrgwMPbYa+oouz8glh+bX1q2MjoN1hteHFLU4knNh5cfbN4oVtW7IjJrnNarHO9CHwXaw5onzRyEdkqjNfJlTzZdF+/3Ui9ETnH+1sqtadcQ


电影名: 蚁人与黄蜂女:量子狂潮-BD1080P/2160P-MP4-中文字幕 磁力名称:
1080P种子蚁人与黄蜂女:量子狂潮-HD1080P-MP4-中文字幕-2.73GB.torrent 下载页面 磁力:
https://www.btsj6.com/down.php?5be1OWlcweGJ9cWanck1gtidYECklpi+KCsOWgr++r6N4TsQhgj+uc3ibq6nTSxoYp9sY7orvl3ZWMBcwUWNHuafX5o9MvZRcF0XlaFp/SaGNeiS00lmfWwVHq+XRbHRTiC0y94jAQJAvZc2rGHu5ly+htx8fei7FGTDCcN3MeheJGts7dzIRG3Ta6uNUrnu/F/WE3hioQjWZcFTMGZXoyaXy97hYLlMR9HxYU+CV792vE3UjPOrecT9+eYDY3zL/g


电影名: 惊奇队长-BD1080P-MP4-中文字幕 磁力名称:
1080P种子惊奇队长-BD1080P-MP4-中文字幕-3.58GB.torrent 下载页面 磁力:
https://www.btsj6.com/down.php?4981edQjHvF9WUOFDu8TFZPaZZCjszif9x3JdepcMJ6KUVv5d4IZnfgq3kph2x3O97yUqk/3B7fExVfH9qK2cPY5kUvqckUgT0mIKyQHFM7rIZtJL/FxN+7C09pIXng7T3fWxCrElrmSa044R0LQKKmZJQYJZ+2ZTsZjU/OoCX5xz8KkuqFk99ovt3eDqiOuCSD0B4A


电影名: 银河护卫队:圣诞特别篇 The Guardians of the Galaxy Holiday
Special-HD1080P-MP4-中文字幕 磁力名称:
1080P种子银河护卫队:圣诞特别篇-HD1080P-MP4-中文字幕-1.95GB.torrent 下载页面 磁力:
https://www.btsj6.com/down.php?fa57/Wzuhp7jPW+xZvkWI/LIqSTzJkFZjR5lC+2LcGuZjf8vLeezi+NyeePgXJIMq+CCO7695ab6XrSoNnfPAmdrCZ71CE9CGDqWjDaJxR9sQ7y+ZE7c6l4IZRH7Sg+xYxsJD+At4teaMREGAn9YOqtMAqCpf0zoKejkGE5AtvrXubEPRNX3DG7EgsoBKWJ6LYSXs/vSA4XNfjeFiia3RpYrqbn3ZCByMyHWyZyEPgUPDymsHs80azA2PSN1YGruGA


电影名: 蜘蛛侠:英雄无归 Spider-Man: No Way Home-BD1080P/2160P-MP4-中文字幕 磁力名称:
4K种子蜘蛛侠:英雄无归 加长版-HD2160P-MP4-中文字幕-6.93GB.torrent 下载页面 磁力:
https://www.btsj6.com/down.php?1155U4R76paMF4MzXecUBu0OzMgBWqLyQtiLAUz0EMVKwEHARqr91SCpEyX2l5wZjXk9PDtaWzD5EuUQevriAKxTL85r0I9x+qypNbfRCIh1pWq7cVlle1TgJ8wkwGcn43rYKoFOlMSqGMW/MwrGXOgGQJgNB2WnsRfO9249McGHD51tPbWQiat7rSgRqoioZUdDSEwAJZji+ku86xuhU4jQeB+xVq9/euWPlU4G/i/+x/U0iw


电影名: 蜘蛛侠:英雄无归 Spider-Man: No Way Home-BD1080P/2160P-MP4-中文字幕 磁力名称:
1080P种子蜘蛛侠:英雄无归-BD1080P-MP4-修正中文字幕-3.87GB.torrent 下载页面 磁力:
https://www.btsj6.com/down.php?edacRaSnL57eji+bawkrsPulEBzqmhqwdARNJ8Ysostgv3m8I4DvVxIVX6OBHadS0a61jIH7bI6ZKkSD6tJu98TTVUN5JqhVGmT7LDO0wClX2bILAzYQMQr3fR3d/sxW3lD2FxNHGQ+UDbKt0u6swLtnPanppcn9xyOktW6E0siihMGhSr6Lm4tC1fN7uKXmwaKZAkDnvfqWJNeKK9DvcJkP/eQVABMg7JkFuoM5YHmF9A


电影名: 我是格鲁特 I Am Groot-1080P全集中文字幕-迅雷下载&在线观看 磁力名称:
第01-05集我是格鲁特.官方中字.I.Am.Groot.S01.1080p.DSNP.WEBRip.DDP5.1.x264-KOGi.mkv
磁力:
magnet:?xt=urn:btih:8ff809d93c817bdf1d9dd5bf71d1012dbb769645&dn=I.Am.Groot.S01.1080p.DSNP.WEBRip.DDP5.1.x264-KOGi[rartv]&tr=http://tracker.trackerfix.com:80/announce&tr=udp://9.rarbg.me:2750&tr=udp://9.rarbg.to:2830&tr=udp://tracker.thinelephant.org:12770&tr=udp://tracker.slowcheetah.org:14790


电影名: 暗夜博士:莫比亚斯 Morbius-BD1080P-MP4-中文字幕 磁力名称:
1080P种子暗夜博士:莫比亚斯-BD1080P-MP4-中文字幕-3.87GB.torrent 下载页面 磁力:
https://www.btsj6.com/down.php?2776tQhxwkcZie6IrLUjkkUuX9siwyt6KSsIQzyJtdSOo6OOgFYNYabsItmmtGcgc76e5dtYX0VVKGtlHVnqS9b7E5M0NYIsRvn4wcKApi+Zxu0czrm1chxS9jv7bH24g7nDIXbGVkYWG8bsdu6JCuhER3fN6bD9uWVFQVWXWMokLuSwmlwP5zmnOF/QuhV6qPLTouL9DiCxT8Y0Q8y6Qjc83dR2mm45IHFv7nSG3PMEeQ


电影名: 暗夜博士:莫比亚斯 Morbius-BD1080P-MP4-中文字幕 磁力名称:
1080P种子暗夜博士:莫比亚斯-HD1080P-MP4-中文字幕-3.35GB.torrent 下载页面 磁力:
https://www.btsj6.com/down.php?32099JTZsCv3JUbSNZ1EItLgCQXw7EO6Rq8Lfrvx2WB9OdKnmBDxeUxEF9JaRzgY3ewJ+a0YoJyMVEm1ohjf9ShrRzj6dzv75cdrQHOQDtGzuaLkjhsxwqJ6gSNwZeEdMHDR8sOHC7gunxyXngZ4VgvVCKUYM2eqdhIP3PSH+461npuUBmlr2Va8T8uBRbRQyE3IhqFqlboewZDe8prSIYz2Bx6doT+oh2ixAZZS3+IsauAR


电影名: 漫威崛起:乐队之战 Marvel Rising: Battle of the Bands-HD1080P-MP4-中文字幕
磁力名称: 1080P种子漫威崛起:乐队之战-HD1080P-MP4-中文字幕-534MB.torrent 下载页面 磁力:
https://www.btsj6.com/down.php?0c89lgmdgutUBZa1AJ+bANsXMJMHi3zqsmEqsmefALQxxr9psm7FfcoAopTmYfNZv0fnqhn/In2DVJ53Xnqzfa6fPBeA0MDdQvesswZqZfaqQJuBZKONqe2u6WE5SA9ugsKGlYe3ir/gsvc1KQhW+99jlDcdQmTtH7fqxto6qCAoK0jn58hSLNJVPOocIzhVPbtLl9m6ba5T7HAOD5bcdZxu+LFRoJZbVJj1cDkVh0FwgPI


电影名: 漫威崛起:火焰游戏 Marvel Rising: Playing with Fire-HD1080P-MP4-中文字幕
磁力名称: 1080P种子漫威崛起:火焰游戏-HD1080P-MP4-中文字幕-637MB.torrent 下载页面 磁力:
https://www.btsj6.com/down.php?64b3+F0kun9B13ev2LbDO/acyTNbxwdwS7fP87o54znqR0mCN+G9a8UTx45d/nh0gUvz0YZXPd/yIA+jwwHTIa+v0ErovLLtx5GpBvtf2TjXy7TzVbxdTCqBE2qJp/YSLAfcKLu29Fmdm6KMFIF6mcOl3ZecqZHwVmM65pmOr83aJJfDmzdvZj4t7OyVPfge17eZqSq7UdIIAOP74TtWXYe+0zbT68sVvsG1tTp7sOUWJrg


电影名: 漫威崛起:苏睿行动 Marvel Rising: Operation Shuri-HD1080P-MP4-中文字幕 磁力名称:
1080P种子漫威崛起:苏睿行动-HD1080P-MP4-中文字幕-423MB.torrent 下载页面 磁力:
https://www.btsj6.com/down.php?93cfu45McKSwd7j8ABntYuBd1aCxH8h3M7kWphFXmHXjRoxzDtggJ1+NtbRefKPx1IknJoZ+GL/7M64Y3AneiA3SYZkV/9qPV+FC75vExKWqi6AYHf3z70p6O6/yfpKhYpa2ePhzCmGdWcwElCTDa2E0txRFEtfbf1tueiEa5ccd1/WcOeVD6hIOOZ/2nBrAPhsNbtQkkf+nwF3AVWgtWiBFsnOUag3qrBlQVreyEcDyxV4


电影名: 永恒族 Eternals-BD1080P-MP4-中文字幕 磁力名称:
1080P种子永恒族-BD1080P-MP4-中文字幕-3.75GB.torrent 下载页面 磁力:
https://www.btsj6.com/down.php?bd1fLkHHLbqrTnrNojlolniBdSNzq+PlYWet4f0kkBnHyqSTQmP13uCbIaL3nki0DOU5XgTSc0LSNmifFB/6vR0OnzhVewcV9zvc1DKV67btfA7pdJ/hf0xxv+bj1jfHW9KRuHeeaqYgdmB92rxAMV+GN31K8YjA19P9ljXIc4qAU0odrEzwg4Csv1TApQ


电影名: 永恒族 Eternals-BD1080P-MP4-中文字幕 磁力名称:
1080P种子永恒族-HD1080P-MP4-中文字幕-3.47GB.torrent 下载页面 磁力:
https://www.btsj6.com/down.php?019bSmWgdiihdRjSNhJiG1vK9NU9ndSBCEtAqceAmWLg2fKQ45AkLQY3c8chiGRSy4qhgEbgsx1MERiqpD163mRrtIJwoN0wSWeVFALVx5Dv28X1h9PQfQPDe1Y6plL9/bYjtSQcYQHkDx0uqR6D6kJ4JKCYoZTAhSnP1ev97YyGSTleSUypAWVfJ2W/DiOK


电影名: 漫威616-全集中文字幕-迅雷下载 磁力名称:
第01集漫威616.Marvels.616.S01E01.WEB-HR.720p.Chs.Eng-Deefun迪幻字幕组-漫威部落字幕组.mp4
磁力:
magnet:?xt=urn:btih:3f9b335a14d926942f64cd4539f7814da878c3f4&tr=http://tr.cili001.com:8070/announce&tr=udp://p4p.arenabg.com:1337&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://open.demonii.com:1337


电影名: 漫威616-全集中文字幕-迅雷下载 磁力名称:
第02集漫威616.Marvels.616.S01E02.WEB-HR.720p.Chs.Eng-Deefun迪幻字幕组-漫威部落字幕组.mp4
磁力:
magnet:?xt=urn:btih:91804f9242aa83cddbe28c8f386377988305bdd8&tr=http://tr.cili001.com:8070/announce&tr=udp://p4p.arenabg.com:1337&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://open.demonii.com:1337


电影名: 漫威616-全集中文字幕-迅雷下载 磁力名称:
第03集漫威616.Marvels.616.S01E03.WEB-HR.720p.Chs.Eng-Deefun迪幻字幕组-漫威部落字幕组.mp4
磁力:
magnet:?xt=urn:btih:0dbf69c120c54ddcc6f709b9f21920e4201d6e5c&tr=http://tr.cili001.com:8070/announce&tr=udp://p4p.arenabg.com:1337&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://open.demonii.com:1337


电影名: 漫威616-全集中文字幕-迅雷下载 磁力名称:
第04集漫威616.Marvels.616.S01E04.WEB-HR.720p.Chs.Eng-Deefun迪幻字幕组-漫威部落字幕组.mp4
磁力:
magnet:?xt=urn:btih:fc64b3bca0332c59b5fa3aa72760bbc83cd08fc3&tr=http://tr.cili001.com:8070/announce&tr=udp://p4p.arenabg.com:1337&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://open.demonii.com:1337


电影名: 漫威616-全集中文字幕-迅雷下载 磁力名称: 第05集第5集 密码:hg6e 磁力:
https://pan.baidu.com/s/1w8321fSIm3uyyKpfjClkhw ****************

你可能感兴趣的:(Python相关,python,爬虫,热榜,磁力搜索,磁力链接,源码,头条新闻)