zoukankan      html  css  js  c++  java
  • python写的笔趣阁网站小说下载器

    import requests
    import re
    from lxml import etree
    # source = requests.get('http://www.paoshu8.com/0_984/746463.html').content.decode('utf8')
    # #print(source)
    # demo = re.compile('<title>(.*?)</title>',re.S)
    # lists = demo.findall(source)
    # demo = re.compile('<div id="content">(.*?)</div>',re.S)
    # contents = demo.findall(source)[0]
    # new_contents = contents.replace('<p>','').replace('</p>',' ')
    # print(new_contents)
    #
    # title = lists[0].split('_')[0]
    # op = open('凡人修仙传.txt','a+')
    # op.write(title+' '+new_contents)
    # op.close()
    c_1 = input('请输入要下载的书籍的关键字:')
    source = requests.get('http://www.biquge.info/modules/article/search.php?searchkey='+c_1).content.decode('utf8')


    # base = etree.HTML(source).xpath('//*[@id="wrapper"]/table//tr/td[1]/a')
    # for i in base:
    # title = i.xpath('text()')
    # hrefs =i.xpath('@href')
    # print(title,hrefs)
    import time
    titles = etree.HTML(source).xpath('//*[@id="wrapper"]/table//tr/td[1]/a/text()')
    hrefs = etree.HTML(source).xpath('//*[@id="wrapper"]/table//tr/td[1]/a/@href')
    n = 1
    for i in titles:
    print(str(n)+' '+i)
    n = n+1
    c_2 = int(input('请输入要下载的书籍序号'))-1
    chapter_page = 'http://www.biquge.info'+hrefs[c_2]
    #print(chapter_page)
    chapter_source = requests.get(chapter_page).content.decode('utf8')
    chapter_lists = etree.HTML(chapter_source).xpath('//*[@id="list"]/dl/dd/a/@href')
    #print(chapter_lists)
    for h in chapter_lists:
    chapter_href = chapter_page+h
    content_source = requests.get(chapter_href).content.decode('utf8')
    title = etree.HTML(content_source).xpath('//h1/text()')[0]
    contents = ' '.join(etree.HTML(content_source).xpath('//*[@id="content"]/text()'))
    print(title)
    print(contents)
    time.sleep(1)
    op = open(titles[c_2]+'.txt','a+',encoding='utf8')
    op.write(title+contents)
    op.close()
    #'//*[@id="wrapper"]/div[4]/div/div[2]/h1'
    #http://www.biquge.info/10_10240/5018128.html

  • 相关阅读:
    Mysql中limit的用法详解
    EXCEPTION与ERROR的区别
    调用sed命令的三种方式
    学编程一定要上大学?美国一半码农都没有计算机学位
    awk 循环语句例子
    Ubuntu 16.04 LTS今日发布
    Ubuntu启动eclipse问题
    Vim技能修炼教程(6)
    Vim技能修炼教程(7)
    Vim技能修炼教程(5)
  • 原文地址:https://www.cnblogs.com/fisherpau/p/14304849.html
Copyright © 2011-2022 走看看