【Python】用番号搜索磁力连接的python源码

<用番号搜索磁力连接的python源码>

用番号搜索磁力连接的python源码代码片段

1. **[代码]~~

#!/usr/bin/env python
#coding=utf8
 
import sys
import urllib2
import re
 
def query_magnet(key):
    try:
 
        #response是HTTPResponse对象
        response = urllib2.urlopen('http://www.btants.cc/q?kw=%s'%(key), timeout=20)
        restr=re.compile(r'''<a(\s*)(.*?)(\s*)href(\s*)=(\s*)([\"\s]*)([^\"\']+?)([\"\s]+)(.*?)>''')
        html=response.read()
        href_list=re.findall(restr,html)
        for href_tup in href_list:
            for href in href_tup:
                if href.find("magnet:?")!=-1:
                    print href
    except Exception, e:
        print e
 
if __name__=="__main__":
    query_magnet(sys.argv[1])

推荐阅读:

零基础入门Python的最详细的源码教程

2019年Python爬虫学习路线图完整版

Python为何能坐稳AI人工智能的头牌语言

Python崛起,TIOBE编程语言排行榜再创新高!

猜你喜欢

转载自blog.csdn.net/kkk123789/article/details/93747727