第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

Python爬蟲批量下載電影鏈接

標簽:
Python

接下来很容易就解析出电影的ftp下载链接和磁力链接:

webp

image

理论部分讲解完成后,接下来的Python实现代码如下:

# -*- coding:utf-8 -*-import urllibimport urllib2import reimport requestsimport timeimport requestsimport requests_cache# User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64)# AppleWebKit/537.36 (KHTML, like Gecko)# Chrome/65.0.3325.181 Safari/537.36 OPR/52.0.2871.64requests_cache.install_cache('demo_cache')global fp
url = 'https://www.dy2018.com/html/gndy/dyzz/index.html'# url = 'https://www.dy2018.com/i/99901.html'user_agent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64)'headers = {'User-Agent': user_agent}try:
    r = requests.get(url)    print type(r)    print r.status_code    print r.encoding

    html = requests.get(url, headers=headers).text
    html = html.encode(r.encoding)
    html = html.decode("gbk")
    content = html    # print content

    fp = open(unicode("temp_pachong.txt", 'utf-8'), 'w')  # 文件名不乱码
    fp.write(content.encode('utf-8'))
    fp.close()    # <a href="/i/99901.html" class="ulink" title="2018年美国7.6分恐怖片《遗传厄运》BD中英双字">2018年美国7.6分恐怖片《遗传厄运》BD中英双字</a>
    pattern = re.compile('<b>.*?<a href="/i/(.*?).html" class="ulink" title="(.*?)">.*?</a>.*?</b>', re.S)
    items = re.findall(pattern, content)

    fp = open(unicode("电影天堂爬虫.txt",'utf-8'),'w')  # 文件名不乱码
    localtime=time.strftime('%Y-%m-%d-%H:%M:%S', time.localtime(time.time()))
    count=0
    fp.write("********************" + localtime +"********************".encode('utf-8') + '\n')    print '本页总资源数为:' + str(len(items))    for item in items:
        count=count+1
        temp=str(count) + ":  " + item[1]        print temp
        fp.write(temp.encode('utf-8')+ '\n')
        temp='https://www.dy2018.com/i/' + item[0] + '.html'
        print temp        #获取下载链接
        url = temp
        r = requests.get(url)
        user_agent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64)'
        headers = {'User-Agent': user_agent}
        html = requests.get(url, headers=headers).text
        html = html.encode(r.encoding)
        html = html.decode("gbk")
        content = html        # print content
        link_temp = re.compile('<td style=".*?"><a href="(.*?)">.*?</a></td>', re.S)
        link = re.findall(link_temp, content)        print link[0]
        fp.write(link[0].encode('utf-8') + '\n')

    fp.write("********************" + localtime +"********************".encode('utf-8'))
    fp.close()except urllib2.URLError, e:    if hasattr(e, "code"):        print e.code    if hasattr(e, "reason"):        print e.reason
    fp.close()

实际效果如下:


webp

view-source_https____i_99901.html.png



作者:看星星的天空
链接:https://www.jianshu.com/p/e9b5518bcdae


點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優(yōu)惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消