运行python脚本,最终程序目录下会是这样:
result.txt中保存所有的URL
文件夹sh.neusoft.com中保存爬虫得到的所有网页
main.py的源代码如下
# -*- coding: utf-8 -*
import os
import re
import shutil
REJECT_FILETYPE = 'rar,7z,css,js,jpg,jpeg,gif,bmp,png,swf,exe'#定义爬虫过程中不下载的文件类型
def getinfo(webaddress):
global REJECT_FILETYPE
url = 'http://'+webaddress+'/'#通过用户输入的网址连接上网络协议,得到URL。