zoukankan      html  css  js  c++  java
  • 爬取一本小说全文

    import requests
    import re
    import time
    
    headers={    
        #'User-Agent':'Nokia6600/1.0 (3.42.1) SymbianOS/7.0s Series60/2.0 Profile/MIDP-2.0 Configuration/CLDC-1.0'
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'
    }
    f=open('C:/Users/Administrator/Desktop/lianxi/doupo.txt','a+')
    
    def get_info(url):
        res=requests.get(url,headers=headers)
        #print(res.content.decode('utf-8')        )
    
        if res.status_code==200:
            contents=re.findall('<p>(.*?)</p>',res.content.decode('utf-8'),re.S)
            for content in contents:
                f.write(content+'
    ')
        else:
            print("失败")
    
    if __name__=='__main__':
        urls=['http://www.doupoxs.com/doupocangqiong/{}.html'.format(str(i)) for i in range(6,9)]
        for url in urls:
            get_info(url)
            time.sleep(1)
    f.close()
  • 相关阅读:
    jQuery-1.样式篇---属性与样式
    jQuery-1.样式篇---选择器
    jQuery-1.样式篇
    随机数
    UIButton
    UILabel
    webView
    气泡聊天
    下拉和上拉刷新
    LimitDemo
  • 原文地址:https://www.cnblogs.com/lanbofei/p/8745338.html
Copyright © 2011-2022 走看看