189 8069 5689

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'    .
    ?
    (.*?)