程序--Python

很开心,自己用Python爬小说看!

import urllib.request
from bs4 import BeautifulSoup

i =253
while i<=369:  
    url = "https://www.hkslg.net/303/303208/63385"+str(i)+".html"  
    #print (url)
    content = urllib.request.urlopen(url).read()
    soup = BeautifulSoup(content,"html.parser")#html.parser
    fo = open("C:/Users/Administrator/Desktop/yh3.txt", "ab+")     #打开小说文件 
    # 以二进制写入章节内容
    fo.write((soup.p).encode('UTF-8'))  
    fo.close()        #关闭小说文件
    i=i+1
    print (i)

虽然很简单,但是比较有感觉。

要自信!要自信!要自信!要自信!要自信!要自信!

20190706

print("666")
import urllib.request
from bs4 import BeautifulSoup

i =163
while i<=763: 
    url = "https://www.yangguiweihuo.com/10/10868/5978"+str(i)+".html" 
    #print (url)
    contents = urllib.request.urlopen(url).read()
    soup = BeautifulSoup(contents,"html.parser")#html.parser
    fo = open("C:/Users/Administrator/Desktop/jys1.txt", "ab+")   #打开小说文件
  # 以二进制写入章节内容
    #print (soup.h1.text)
    fo.write(soup.h1.text.encode())
    for k in soup.find_all('div',class_='showtxt'):#,string='更多'
        #print(k.text)       
        date = k.text.replace("https://www.yangguiweihuo.com/10/10868/5978", "\n ")
        date = date.replace(str(i), "\n ")
        date = date.replace(".htmlchaptererror();请记住本书首发域名:www.yangguiweihuo.com。笔趣阁手机版阅读网址:m.yangguiweihuo.com", "\n ")
        fo.write(date.encode()) 
    fo.close()    #关闭小说文件
    i=i+1
    print (i)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值