本文实例讲述了python实现爬虫抓取小说功能。分享给大家供大家参考,具体如下:
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
from urllib import request
import re
import os,time
#访问url,返回html页面
def get_html(url):
req = request.Request(url)
req.add_header('User-Agent','Mozilla/5.0')
response = request.urlopen(url)
html =
1