V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
xinmans
V2EX  ›  Python

如何基于 Python 的一些库下载 rmdown 的种子

  •  
  •   xinmans · 2023-06-08 21:42:14 +08:00 · 1131 次点击
    这是一个创建于 539 天前的主题,其中的信息可能已经有所发展或是发生改变。
    6 条回复    2023-06-11 13:43:21 +08:00
    xinmans
        1
    xinmans  
    OP
       2023-06-08 21:42:53 +08:00
    import time
    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service
    from selenium.webdriver.common.by import By
    import pyperclip
    from fake_useragent import UserAgent

    from random import randint

    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver import ActionChains
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.common.exceptions import TimeoutException


    def get_random_user_agent():
    ua = UserAgent()
    user_agent = ua.random
    headers = {"User-Agent": user_agent}
    return headers


    # 设置 Chrome 浏览器路径和 options
    s = Service("/usr/local/bin/chromedriver")
    chrome_options = Options()
    torrents_path = "./"
    prefs = {'savefile.default_directory': torrents_path}
    chrome_options.add_experimental_option('prefs', prefs)
    chrome_options.add_argument('--headless=new')
    user_agent = get_random_user_agent()['User-Agent']
    chrome_options.add_argument(f'user-agent={user_agent}')
    chrome_options.add_argument('--disable-gpu')
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--disable-dev-shm-usage')
    chrome_options.add_argument('--aggressive-cache-discard')
    chrome_options.add_argument('--disable-cache')
    chrome_options.add_argument('--disable-application-cache')
    chrome_options.add_argument('--disable-offline-load-stale-cache')
    chrome_options.add_argument('--disable-gpu-shader-disk-cache')
    chrome_options.add_argument('--media-cache-size=0')
    chrome_options.add_argument('--disk-cache-size=0')
    chrome_options.add_experimental_option("excludeSwitches", ['enable-automation', 'enable-logging'])
    driver = webdriver.Chrome(service=s, options=chrome_options)

    # 访问 RMDown 网站并点击复制按钮
    url = 'https://www.rmdown.com/link.php?hash=232416715dfa1b4fa7c38fa3d187c664446ae57be3c'
    driver.get(url)
    time.sleep(2) # 等待页面加载

    try:
    driver.get(url)
    time.sleep(2) # 等待页面加载
    driver.find_element(
    "xpath", "//button[@type='submit'][@title='Download file']").click()
    time.sleep(2) # 等待页面加载
    driver.maximize_window()
    driver.quit()
    except Exception as e:
    print(" Connected failure: %s" % e)

    # 关闭浏览器
    driver.quit()


    总是报错
    elboble
        2
    elboble  
       2023-06-08 23:14:55 +08:00 via Android
    好像去掉 232 就是 magnet
    Trim21
        3
    Trim21  
       2023-06-08 23:26:57 +08:00
    把 url query 的 hash 去掉前三个字符就能拼出磁链了
    xinmans
        4
    xinmans  
    OP
       2023-06-11 13:42:35 +08:00 via iPhone
    @Trim21 没懂,hash 直接转换成 magnet ?
    xinmans
        5
    xinmans  
    OP
       2023-06-11 13:42:49 +08:00 via iPhone
    @elboble 这么神奇?
    xinmans
        6
    xinmans  
    OP
       2023-06-11 13:43:21 +08:00 via iPhone
    @xinmans 懂了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2876 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 15:13 · PVG 23:13 · LAX 07:13 · JFK 10:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.