鱼C论坛

 找回密码
 立即注册
查看: 5286|回复: 1

[已解决]请帮忙看一下这个磁链下载代码为何不能使用,谢谢

[复制链接]
发表于 2017-8-9 14:42:21 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
import urllib.request
import re
import random

def open_url(url):
    req = urllib.request.Request(url)
    req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36')
    proxies = ['171.214.248.246:8118', '123.130.11.82:8118', '42.55.174.146:80']
    proxy = random.choice(proxies)
    proxy_support = urllib.request.ProxyHandler({'http':proxy})
    opener = urllib.request.build_opener(proxy_support)
    urllib.request.install_opener(opener)
    response = urllib.request.urlopen(req)
    html = response.read()
    return html

def get_magnet(html):
    p = r'<a href="(.+)" title=".+" rel="magnet">'
    result = re.findall(p,html)
    for each in result:
        print(each)

if __name__ == '__main__':
    fh = input('Please enter the FH:')
    url = 'https://www.torrentkitty.tv/search/' +fh
    get_magnet(open_url(url))
最佳答案
2017-8-9 23:36:15
  1. import urllib.request
  2. import re
  3. from urllib import parse

  4. def open_url(url):
  5.     req = urllib.request.Request(url)
  6.     req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36')
  7.     response = urllib.request.urlopen(req)
  8.     html = response.read().decode('utf-8')
  9.     return html

  10. def get_magnet(html):
  11.     p = r'<a href="(magnet:\?xt=urn:btih:[^"]+)'
  12.     result = re.findall(p,html)
  13.     for each in result:
  14.         print(each)

  15. if __name__ == '__main__':
  16.     fh = input('Please enter the FH:')
  17.     url = 'https://www.torrentkitty.tv/search/' + parse.quote(fh)+'/'
  18.     get_magnet(open_url(url))
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-8-9 23:36:15 | 显示全部楼层    本楼为最佳答案   
  1. import urllib.request
  2. import re
  3. from urllib import parse

  4. def open_url(url):
  5.     req = urllib.request.Request(url)
  6.     req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36')
  7.     response = urllib.request.urlopen(req)
  8.     html = response.read().decode('utf-8')
  9.     return html

  10. def get_magnet(html):
  11.     p = r'<a href="(magnet:\?xt=urn:btih:[^"]+)'
  12.     result = re.findall(p,html)
  13.     for each in result:
  14.         print(each)

  15. if __name__ == '__main__':
  16.     fh = input('Please enter the FH:')
  17.     url = 'https://www.torrentkitty.tv/search/' + parse.quote(fh)+'/'
  18.     get_magnet(open_url(url))
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-21 19:05

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表