Python抓取美劇天堂bt

使用urllib,urllib2,beautifulsoup.

執(zhí)行下面代碼,輸入要查找的美劇名即可:

查詢到所有結(jié)果并遍歷每一個結(jié)果中不同視頻格式的所有下載鏈接

# coding: utf-8

import urllib

import urllib2

from bs4 import BeautifulSoup

import sys

reload(sys)

sys.setdefaultencoding('utf8')

host= "http://www.meijutt.com"

def getUrlRespHtml(url,data=None):

? ?heads = {'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',

? ? ? ? ? ?'Accept-Charset':'GB2312,utf-8;q=0.7,*;q=0.7',

? ? ? ? ? ?'Accept-Language':'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',

? ? ? ? ? ?'Cache-Control':'max-age=0',

? ? ? ? ? ?'Host':host,

? ? ? ? ? ?'Connection':'keep-alive',

? ? ? ? ? ?'Referer':url,

? ? ? ? ? ?'User-Agent':'Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.14) Gecko/20110221 Ubuntu/10.10 (maverick) Firefox/3.6.14'}

? ?req = urllib2.Request(url)

? ?opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())

? ?opener.addheaders = heads.items()

? ?if data:

? ? ? ?data = urllib.urlencode(data)

? ? ? ?respHtml = opener.open(req,data).read()

? ?else:

? ? ? ?respHtml = opener.open(req).read()

? ?return respHtml

def get_bt(url):

? ?html = getUrlRespHtml(url)

? ?bs_html = BeautifulSoup(html)

? ?download_list = bs_html.find_all('div','down_list')

? ?for index,down_list in enumerate(download_list):

? ? ? ?if len(download_list)>1:

? ? ? ? ? ?print '<<<<<視頻格式%s>>>>>'%(index+1)

? ? ? ?for li in down_list.find_all('li'):

? ? ? ? ? ?f_attrs = li.find('input','down_url').attrs

? ? ? ? ? ?print f_attrs.get('value')

def get_bts(searchword):

? ?data ={'searchword':searchword}

? ?url = host+'/search.asp'

? ?html=getUrlRespHtml(url,data)

? ?bs = BeautifulSoup(html)

? ?cn_box2 = bs.find_all('div','cn_box2')

? ?print '\n搜索結(jié)果:%s\n'%len(cn_box2)

? ?for index,div in enumerate(cn_box2):

? ? ? ?print '------搜索結(jié)果%s------'%(index+1)

? ? ? ?attrs = div.a.attrs

? ? ? ?title = attrs.get('title')

? ? ? ?href = attrs.get('href')

? ? ? ?print title,(host+href)

? ? ? ?get_bt(host+href)

? ? ? ?print '------end--------\n'

searchword=raw_input("請輸入要搜索的美劇:")

get_bts(searchword.encode('gb2312'))

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容