Skip to content

Instantly share code, notes, and snippets.

@xdqi
Created April 1, 2014 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save xdqi/9908156 to your computer and use it in GitHub Desktop.
Save xdqi/9908156 to your computer and use it in GitHub Desktop.
Print all magnet links on a KTXP search page
#!/usr/bin/env python
# Using: getktxp.py [KTXP Search Page URL]
# TODO:
# 1. Merge it with lixian-cli
# 2. Support Multi Pages (I did not implement that because typical anime series has less than 30 episodes)
import sys
from bs4 import BeautifulSoup
import requests
import urllib
import re
from HTMLParser import HTMLParser
#import os
z = requests.get(sys.argv[1])
y = BeautifulSoup(z.text)
x = y.select('td.ltext.ttitle')
for w in x:
a = requests.get('http://bt.ktxp.com/%s' % w.select('a')[1]['href'])
b = BeautifulSoup(a.text)
c = b.select('div.right.clear script')[0].text
d = HTMLParser.unescape.__func__(HTMLParser, urllib.unquote(c))
e = re.findall(r'"(magnet:.+)"', d)[0]
print e
#os.system('python lixian-cli.py add %s' % e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment