#!/usr/bin/python
2 import urllib
3 import urllib2
4 import re
5 import os
6
7 dirs = ['js','img','pay','css']
8 urls = ['http://www.xxxxxx.net/' + x for x in dirs]
9
10 def parse(baseurl):
11 url_hand = urllib2.urlopen(baseurl)
12 url_cont = url_hand.read()
13 urllist = re.findall("<A HREF=\".*\">",url_cont)
14 files = []
15 dirs = []
16 cwd = os.getcwd()
17 for x in urllist:
18 xx = x.split("\"")[1]
19 if re.search(".*/$",xx):
20 dirs.append(xx)
21 nextpath = os.path.join(cwd, xx)
22 else:
23 files.append(xx)
24 dirs.remove(dirs[0])
25
26
27 for xfile in files:
28 xfileurl = "http://www.xxxxxx.net" + xfile
29 #todir = os.path.join(pardir, os.path.dirname(xfile))
30 todir = cwd + xfile
31 print todir
32 urllib.urlretrieve(xfileurl, todir)
33 for xdir in dirs:
34 todir = cwd + xdir
35 try:
36 os.mkdir(todir)
37 except OSError, e:
38 print "dir exist!!"
39 xdirurl = "http://www.xxxxxx.net" + xdir
40 print xdirurl
41 parse(xdirurl)
42
43
44 if __name__ == "__main__":
45 for url in urls:
46 parse(url)

知识点:

1.这个站点有autoindex,所以进入目录后自动列出里面的文件,将其爬出,分类,文件,和目录

对于文件,直接抓取。

对于目录,得到路径后对其调用函数递归抓取。

2.下载文件,可以使用urllib模块的urlretrieve

3.还可以使用urlopen->read->write to file

[python]爬站点的更多相关文章

  1. 利用python爬取城市公交站点

    利用python爬取城市公交站点 页面分析 https://guiyang.8684.cn/line1 爬虫 我们利用requests请求,利用BeautifulSoup来解析,获取我们的站点数据.得 ...

  2. 用Python爬E站本

    用Python爬E站本 一.前言 参考并改进自 OverJerry 大佬的 教你怎么用Python爬取E站的本子_OverJerry. 本文为技术学习记录,不提供访问无存在网站的任何方法,也不包含不和 ...

  3. 用Python爬取网易云音乐热评

    用Python爬取网易云音乐热评 本文旨在记录Python爬虫实例:网易云热评下载 由于是从零开始,本文内容借鉴于各种网络资源,如有侵权请告知作者. 要看懂本文,需要具备一点点网络相关知识.不过没有关 ...

  4. Python 爬取所有51VOA网站的Learn a words文本及mp3音频

    Python 爬取所有51VOA网站的Learn a words文本及mp3音频 #!/usr/bin/env python # -*- coding: utf-8 -*- #Python 爬取所有5 ...

  5. python爬取网站数据

    开学前接了一个任务,内容是从网上爬取特定属性的数据.正好之前学了python,练练手. 编码问题 因为涉及到中文,所以必然地涉及到了编码的问题,这一次借这个机会算是彻底搞清楚了. 问题要从文字的编码讲 ...

  6. python爬取某个网页的图片-如百度贴吧

    python爬取某个网页的图片-如百度贴吧 作者:vpoet mail:vpoet_sir@163.com 注:随意copy,不用告诉我 #coding:utf-8 import urllib imp ...

  7. python爬爬爬之单网页html页面爬取

    python爬爬爬之单网页html页面爬取 作者:vpoet mail:vpoet_sir@163.com 注:随意copy 不用告诉我 #coding:utf-8 import urllib2 Re ...

  8. Python:爬取乌云厂商列表,使用BeautifulSoup解析

    在SSS论坛看到有人写的Python爬取乌云厂商,想练一下手,就照着重新写了一遍 原帖:http://bbs.sssie.com/thread-965-1-1.html #coding:utf- im ...

  9. 使用python爬取MedSci上的期刊信息

    使用python爬取medsci上的期刊信息,通过设定条件,然后获取相应的期刊的的影响因子排名,期刊名称,英文全称和影响因子.主要过程如下: 首先,通过分析网站http://www.medsci.cn ...

随机推荐

  1. HTML+JS = 网站注册界面源代码

    本注册页面未设置编码方式和兼容性,已测试,在Chrome浏览器显示正常 <!DOCTYPE html> <html> <head> <title>注册页 ...

  2. python邮件服务-yagmail

      下载安装 yagmail import yagmail #链接邮箱服务器 #此处的password是授权码 yag= yagmail.SMTP( user="843092012@qq.c ...

  3. Linux 添加虚拟网卡

    使用的Linux版本是Centos 7: [root@vnode33 bin]# cat /etc/redhat-release CentOS Linux release (Core) 使用ifcon ...

  4. oracle数据库之PL/SQL 块结构和组成元素

    一.PL/SQL 块 (一)PL/SQL 程序由三个块组成,即声明部分.执行部分.异常处理部分 PL/SQL 块的结构如下: 1.DECLARE /* 声明部分: 在此声明 PL/SQL 用到的变量, ...

  5. java键盘IO

    public class IO { public static void main(String[] args) throws Throwable { ScannerTest(); // testSc ...

  6. 一起写一个Android图片轮播控件

    注:本文提到的Android轮播控件Demo地址: Android图片轮播控件 1. 轮播控件的组成部分 我们以知乎日报Android客户端的轮播控件为例,分析一下轮播控件的主要组成: 首先我们要有用 ...

  7. django 安装/部署过程

    一.软件安装 1.升级linux中的python   参考“centos升级python” 2.安装apache(httpd) 3.安装django,先要安装setuptools    参考“安装dj ...

  8. checkBox1_CheckedChanged(object sender, EventArgs e)和checkBox1_CheckStateChanged(object sender, EventArgs e)不同

    using System; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms ...

  9. [C/C++] C/C++错题集

    1. 解析: A:在GCC下输出:0    在VC6.0下输出:1 B:在GCC下输出:段错误 (核心已转储)    在VC6.0下输出:已停止工作,出现了一个问题,导致程序停止正常工作. C:正常 ...

  10. 【Python】Python中的下划线

    单下划线(如: _var): 使用单下划线,用于指定该名变量或函数属性为“私有”.这仅仅是一个惯例,不是强制规定.用于向其他程序员表明这个变量或函数仅仅供内部使用,外部不要访问它.但实际上外部还是可以 ...