• Python 爬虫实例(5)—— 爬取爱奇艺视频电视剧的链接(2017-06-30 10:37)


    1. 我们找到  爱奇艺电视剧的链接地址

      

      http://list.iqiyi.com/www/2/-------------11-1-1-iqiyi--.html

          我们点击翻页发现爱奇艺的链接是这样的规律

      http://list.iqiyi.com/www/2/-------------11-2-1-iqiyi--.html

      http://list.iqiyi.com/www/2/-------------11-3-1-iqiyi--.html

    2. 我们分析  http://list.iqiyi.com/www/2/-------------11-1-1-iqiyi--.html    请求过程

        

    3.最后 粘贴出来代码

    # coding:utf-8
    
    import re
    import json, time
    from bs4 import BeautifulSoup
    
    import sys
    reload(sys)
    sys.setdefaultencoding('utf-8')
    
    import requests
    
    session = requests.session()
    
    def aiqiyi():
    
        for i in range(1,2000):
            url = "http://list.iqiyi.com/www/2/-------------11-"+ str(i) +"-1-iqiyi--.html"
            if i == 1:
                Referer = "http://list.iqiyi.com/www/2/-------------11-"+ str(i) +"-1-iqiyi--.html"
            else:
                Referer = "http://list.iqiyi.com/www/2/-------------11-" + str(i-1) + "-1-iqiyi--.html"
    
    
            headers = {
    
                    "Host":"list.iqiyi.com",
                    "Connection":"keep-alive",
                    "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
                    "Upgrade-Insecure-Requests":"1",
                    "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36",
                    "Referer":Referer,
                    "Accept-Encoding":"gzip, deflate, sdch",
                    "Accept-Language":"zh-CN,zh;q=0.8",
                }
    
            result = session.get(url=url,headers=headers).text
    
            soup = BeautifulSoup(result, 'html.parser')
            returnSoup = soup.find_all("div", attrs={"class": "wrapper-piclist"})[0]
            returnSoup1= str(returnSoup).replace('
    ','').replace('
    ','').replace(' ','').replace('"rseat="bigTitle','')
    
            href_title = re.findall('"data-widget-qidanadd="qidanadd"href="(.*?)"target="_blank"title=".*?"><imgalt="(.*?)"height="236"rseat="dsjp7"src=',str(returnSoup1))
    
            for i in href_title:
                href = i[0]
                title = i[1]
    
    
                href = str(href).split('#')[0]
                headers = {
    
    
                            "Connection":"keep-alive",
                            "Accept-Encoding":"gzip, deflate, sdch",
                            "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
                            "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36",
                            "Accept-Language":"zh-CN,zh;q=0.8",
                            "Host":"www.iqiyi.com",
                            "Upgrade-Insecure-Requests":"1",
    
                        }
                result2 = session.get(url=href,headers=headers).text
    
    
                result3 = str(result2).replace('
    ','').replace('  ','').replace('
    ','').replace('    ','').replace(' ','')
                resultre = re.findall('<pclass="site-piclist_info_title"><ahref="(.*?)"rseat="705233_title"target="_blank">(.*?)</a></p>',str(result3))
    
                for i in resultre:
                    print i[0],i[1],"-----------",title
    
                time.sleep(2000)
    
    
    
    aiqiyi()


    输出的结果是:

    C:Python27python.exe C:/Users/xuchunlin/PycharmProjects/study/app/project/aiqiyiUrl.py
    http://www.iqiyi.com/v_19rr91tio0.html 第1集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr91wki8.html 第2集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr91d9o0.html 第3集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr91c0yg.html 第4集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr90uigk.html 第5集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr90t1gc.html 第6集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8qb2ow.html 第7集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8q9fi4.html 第8集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8pr00c.html 第9集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8p0qdc.html 第10集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8occ3k.html 第11集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8npdfc.html 第12集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8nq9qw.html 第13集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8mzwhw.html 第14集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8n3c9k.html 第15集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8mcd7o.html 第16集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8mczus.html 第17集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8lscsk.html 第18集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8lq2c8.html 第19集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8v32rw.html 第20集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8uhouw.html 第21集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8tpcss.html 第22集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8t439c.html 第23集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8t1sdw.html 第24集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8sgdug.html 第25集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8sjsvc.html 第26集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8rx3j8.html 第27集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8rvxm0.html 第28集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8r96f0.html 第29集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8rdces.html 第30集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8qrzs4.html 第31集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rrdzwrsw.html 第32集 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8qw4r4.html 第33集预告 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8qqp08.html 第34集预告 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr8n78oo.html 第35集预告 ----------- 美味奇缘
    http://www.iqiyi.com/v_19rr92rmic.html 第36集预告 ----------- 美味奇缘
    1

        

  • 相关阅读:
    规划支持系统的现状与发展方向
    环境影响评价的概念和指标体系
    DTD to XSD的在线免费转换工具
    如何在64位IIS中启用32位支持
    Entity Framework 1.0中的日期比较
    安装Office 2010 beta后Visual Studio 2008的Web设计器失去响应的问题
    为何由WSDL.exe生成的Web服务代理类无法正确的序列化枚举类型?因为……
    如何为一个XML文件进行DTD验证
    释放VB.NET下Linq to XML的智能提示的威力
    Entity Framework概述 For 终结者
  • 原文地址:https://www.cnblogs.com/xuchunlin/p/7235970.html
Copyright © 2020-2023  润新知