资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

python超简化的18行代码爬一本小说

import urllib.request
import re
def getnvvel():
html = urllib.request.urlopen("http://www.quanshuwang.com/book/44/44683").read().decode('gbk') # download sould code
urls = re.findall(r'

  • (.?)
  • ', html) # regular expression
    title = "douluo" # Normoally,you should use request.urlopen
    f = open('../novel/%s.txt' % title, 'w') # create a douluo.txt
    for url in urls:
    chapter_url = url[0]
    chapter_title = url[1]
    chapter_content_list = urllib.request.urlopen(chapter_url).read().decode("gbk")
    chapter_content_list = re.findall(r'    .
    ?
    (.*?)