UUBlog

UUBlog

Windows下有很多优秀的录屏工具,前一天,我为了录个GIF,又开了自己的Windows 10.

现在的Ubuntu,越来越优秀了,很多Windows的工具,都能在这里找到替代品,我用Windows似乎越来越少了。

但是两个系统都有自己的优势,都有一些好用到哭的软件。

录屏这方面,其实我用比较多也就OBS StudioCamtasia Studio,推荐的也就这两个比较多。

前者一般我用于录MP4格式的,后者用于录制GIF。录出来的体积小得感人,清晰度也不错。

OBS现在已经有了for linux版本,提前走向了all platform。Camtasia还没有Linux版本,倒是有了Mac版的。

这让我很眼红Mac。Gif有时候还是要录制的,Linux下有没有过得去的替代品呢?

一番查找还是有的。比如byzanzpeekOBS+ffmepg等等,还有ttyrc这等奇葩。

byzanz

这个工具录制出来体积其实是最小的,但是有个很不方便的地方,就是必须先设定录制时长。

我特么大多时候怎么知道我录制屏幕要多久。不过这个就作为备选方案吧,毕竟有时候我还是知道我应该录多久的。

1
2
sudo apt install byzanz

peek

相对于 byzanz,有好用的GUI界面,简单的操作,可以拖动选定录制区域,自由决定录制时间。

这个也是我个人的主选方案

安装:

1
2
3
4
sudo add-apt-repository ppa:peek-developers/stable
sudo apt update
sudo apt install peek

OBS+ffmepg

这个我逗你玩。正常情况下,录制MP4再转GIF体积会比MP4还要大。不过如果用OBS录制的时候,调低速率,和减少每秒的帧数,再转换,还是能有不错的体积的。但是,麻不麻烦?

关注公众号 尹安灿

今天老板请团队吃饭,我和小林瞎侃,聊到信息安全。

突然想到之前上线每次都是整个目录复制发布,很有可能存在svn信息泄露问题。

最近一直在忙着架构方面的东西,把这茬的测试给忘了。

一回到家就开了电脑测试,惊出一身冷汗,简直是核弹。

话不多说,看图,

SVN LEAKING information

这里面图片仅仅是展示能够根据这些东西读取出文件目录。这里就发现了一个备份数据库。

实际危害比图片看到的大得多。

这件事情也是对我敲响了一个警钟,安全问题,还是刻不容缓。

怎么修复?

  • 治标方法,删除所有.svn目录。

    进入要发布的目录执行,会将所有.svn目录删除

    1
    2
    find . -type d -name '.svn' | xargs rm -rf

  • 治本方法,规范整个代码发布流程。

    比如walle。如果用svn这类代码版本管理工具,最好用导出功能,别直接复制,.svn是隐藏目录。或者发布的时候,自己过滤掉这类敏感文件。

  • 未雨绸缪, 设置web服务器拒绝访问这类后缀的文件,顺便把sql文件也捎上。

    nginx -t 可以找到你的nginx配置文件

    1
    2
    3
    4
    5
    6
            location ~ .*.(svn|git|cvs|sql) {
    deny all;
    }

    #nginx -s reload

搞定,睡觉,明天估计要修改一大堆东西。

相关工具下载

SVN泄露文件利用工具

其实工具展示的信息是阉割版的了。有兴趣的自己下载相关文件分析,信息量爆炸。

关注公众号 尹安灿

最近公司有这么一个需求。某ERP并发不高,web数据不大,单台服务器就能满足需求,暂时不需要负载均衡。

但是有对于服务高可用和数据安全需求比较高。所以想搞多一台服务器做灾备,实现高可用和数据备份。

选择服务器

目前业务主要面向华南地区的店,所以服务器得选华南地区的。

主服务在阿里云,从服务器也选阿里云,方便管理,内网同步速度略优。缺点就是阿里云出问题,大家一起挂,另外使用同个账户管理的机器,账户泄露两个机子都遭殃。

选非阿里云的服务器,能更大程度避免单点故障情况发生,缺点是管理略为麻烦,同步可能会稍微慢一点点,占用出口带宽,

怎么备份

目前打算至少存在两份异地备份。一份高频近乎实时同步的备份,一份低频定时备份到运维人员机子本地。

前面高频备份是高可用的基础,否则单点故障,备份服务器不能提供完整的数据。

而低频的本地备份可以在出现恶意的攻击,删库等行为后,依然有数据。

而这次备份的重点也是在线的同步备份。

昨天尝试使用 inotify-tools + rsync 用来发现创建修改文件等动作,然后触发 rsync 进行同步。

业务需求能满足,但是不好的是,每次事件触发都进行一次全局扫描,然后坐差异备份有点耗资源。

假如一次性通过命令创建几千个命令,那可能会触发几千次同步。

我想遇到这个问题的肯定不是我一人,度娘之,果然有针对这个问题的解决方案,那就是 sersync + rsync

根据设想的备份流程做了如下图 (绘图软件 dia 不能输入中文 囧)
备份流程图

  1. ERP服务器上运行 sersync 当inotify发现文件读写相关事件的时候,就向备份服务器发起同步,进行差异备份。

  2. 运维定时主动向备份服务器发起同步请求,同步备份数据回本地。

服务器配置

备份服务器配置

  1. 新建一个账户sync_backup作为同步的专用账户,设置用户shell为/sbin/nologin,直接用root太危险了,这样就算密码泄露了,也不会直接导致系统沦陷。
1
2
3
useradd sync_backup -s /sbin/nologin
passwd sync_backup --stdin #建议用密码生成工具生成一个足够强壮的密码复制黏贴过来。

  1. 配置rsync服务

这玩意,你得指定它备份的项目名字,路径,用哪个账户验证,指定认证用户的密码文件。

并设置将密码文件权限设置为600,保证只有root用户才能获取它内容。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[root@yzy ~]# vim /etc/rsyncd.conf
# 2017-03-27 By YYY
uid = root
gid = root
use root = true
use chroot = no # 限制用户只能在备份目录
transfer logging = true
read only = no
max connections = 3600
slp refresh = 300
hosts allow = 1X0.X6.1X8.XXX # 源服务器IP 只允许源服务器连接
host deny = 0.0.0.0/32
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
##log format = %h %o %f %l %b
#
[web]
path = /www/web # 备份根路径
comment = Mirror to web server
list = false
read only = no # 设置非只读
auth users = sync_backup # 指定认证用户
secrets file = /etc/rsyncd.secrets # 指定密码文件
##exclude from = /etc/rsync/exclude.txt # 排除不做同步的列表 这里注释了 有需要再启用

密码文件

1
2
#vim /etc/rsyncd.secrets
sync_backup:用户密码
1
2
chmod 600 /etc/rsyncd.secrets

  1. 启动rsync的守护进程并设置开机启动

尽量用vim改 别echo 误操作一次就坑爹了,别问我为什么特别注明这个

1
2
3
4
#/usr/bin/rsync --deamon
#vim /etc/rc.local
/usr/bin/rsync --deamon

配置源服务器

为什么是先配置备份服务器的rsync,这样可以到源服务器,先尝试先同步看看备份服务器看看是否能正确同步。

这样利于一步一步排错。

1
2
sudo #rsync -avzP /测试同步的目录/ --password-file=/etc/rsyncd.secrets sync_backup@备份服务IP::web/

/etc/rsyncd.secrets 格式 密码,直接就是密码。

我这里测试没问题,就接着部署了sersync

部署sersync

  1. 下载安装 sersync

由于上Google Code要翻墙,我从GitHub下载了一份。

1
2
wget --no-check-certificate https://raw.githubusercontent.com/orangle/sersync/master/release/sersync2.5.4_64bit_binary_stable_final.tar.gz

Google Code sersync项目地址

sersync项目GitHub镜像

下载项目、解压、移动去 /usr/local/sersync/

1
2
3
4
wget --no-check-certificate https://raw.githubusercontent.com/orangle/sersync/master/release/sersync2.5.4_64bit_binary_stable_final.tar.gz
tar zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz
sudo mv GNU-Linux-x86/ /usr/local/sersync/

  1. 配置sersync

关键的配置我都已经注释了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<debug start="false"/>
<fileSystem xfs="false"/>
<filter start="true"> # 开启文件过滤
<exclude expression="(.*)\.svn"></exclude> # 过滤内容 有些敏感文件不同步
<exclude expression="(.*)\.gz"></exclude>
<!--exclude expression="^info/*"></exclude-->
<!--exclude expression="^static/*"></exclude-->
</filter>
<inotify> # 监控哪些事件 默认就好
<delete start="true"/>
<createFolder start="true"/>
<createFile start="false"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="false"/>
<modify start="false"/>
</inotify>

<sersync>
<localpath watch="/www/web/shixin_dev_sync_test"> # 需要同步的目录
<remote ip="123.184.19.202" name="web"/> # 备份服务器信息
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-artuz"/> # rsync 参数
<auth start="true" users="sync_backup" passwordfile="/etc/rsyncd.secrets"/> # 备份服务器账户信息 记得 开启 true
<userDefinedPort start="false" port="874"/><!-- port=874 --> 备份的默认端口
<timeout start="false" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
<crontab start="false" schedule="600"><!--600mins-->
<crontabfilter start="false">
<exclude expression="*.php"></exclude>
<exclude expression="info/*"></exclude>
</crontabfilter>
</crontab>
<plugin start="false" name="command"/>
</sersync>

<plugin name="command">
<param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix-->
<filter start="false">
<include expression="(.*)\.php"/>
<include expression="(.*)\.sh"/>
</filter>
</plugin>

<plugin name="socket">
<localpath watch="/opt/tongbu">
<deshost ip="192.168.138.20" port="8009"/>
</localpath>
</plugin>
<plugin name="refreshCDN">
<localpath watch="/data0/htdocs/cms.xoyo.com/site/">
<cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>
<sendurl base="http://pic.xoyo.com/cms"/>
<regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
</localpath>
</plugin>
</head>

  1. 启动并设置开机启动
1
2
3
4
sudo /usr/local/sersync/sersync2 -r -d -o /usr/local/sersync/confxml.xml # 启动守护进程
vim /etc/rc.local
/usr/local/sersync/sersync2 -r -d -o /usr/local/sersync/confxml.xml

参考资料

关注公众号 尹安灿

讯云这几天搞活动,免费领了三个月的免费VPS。所以想把本地虚拟机的scrapy爬虫迁移上去。

Scrapy是基于Python写的。本来是要安装Python的,但是现在Linux基本都默认安装到Python了,所以这步略过。

我本地是Ubuntu,服务器我装了CentOS7.2。别问我为啥不用Debian,我瞎选的,没啥特别理由。

自己私人使用,为了方便,直接是root开干。

  1. 安装pip包管理
1
2
yum install -y python-pip

  1. 配置pip安装源为阿里云 http://mirrors.aliyun.com/help/pypi

我觉得这是天朝必备的一个步骤,否则安装软件那龟速不忍直视。

1
2
3
4
5
6
7
8
9
10
mkdir ~/.pip
vim ~/.pip/pip.conf

# 改为如下内容
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com

3, 安装编译器和开发库之类的,假如你们也没安装的话

1
2
yum -y install gcc gcc-c++ kernel-devel python-devel libxslt-devel libffi-devel openssl-devel

  1. 安装主角Scrapy
1
2
pip install scrapy

  1. 安装MySQL-python

Python连接MySQL的模块

1
2
easy_install MySQL-python

如果遇到mysql_config not found
之前的博文有提过这个错误,不过是在Ubuntu下的解决方案-安装libmysqlclient-dev
然而在CentOS的源中并没有这个包。而安装mysql-devel即可。

1
2
yum install -y mysql-devel

  1. 安装MySQL数据库 yum groupinstall mariadb mariadb-client

MariaDB其实可以看做MySQL新版吧,具体缘由自行百度。

  1. 安装redisNoSQL数据库
    会用到配合bloomfilter做url去重。
1
2
yum install -y redis

  1. 安装 BloomFilter 模块
1
2
pip install bloomfilter

至此就差不多了,目前我就用到这些,另外requests和beautifulsoup4模块也装一下。

关注公众号 尹安灿

采集到的数据,总归是要保存起来,保存到文件,或者数据库,方便以后取用。

思前想后,还是决定采用MySQL数据库,新版本叫MariaDB了,不过都是通用的。

安装MySQL-python模块

1
sudo easy_install MySQL-python

Issue:安装MySQL-Python出错mysql_config not found

插入数据

我这里MySQL位于我虚拟机172.25.254.18,数据库名yzy_data,用户名yzy_data,密码pass

我新建了一个表用于保存标题用户ID网盘URL
表结构如下

1
2
3
4
5
6
7
8
9
10
11
12
13
CREATE TABLE `test` (
`id` int(11) NOT NULL,
`title` varchar(255) NOT NULL,
`uid` varchar(30) NOT NULL,
`purl` varchar(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;

ALTER TABLE `test`
ADD PRIMARY KEY (`id`);

ALTER TABLE `test`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

新增了一个ID的字段,方便索引数据,这个字段我设置是自增的,所以平时插入数据留空即可。

插入一条数据,标题:测试插入、用户ID:123321、网盘URL:http://pan.baidu.com/xxx

代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 导入mysql库
import MySQLdb

#连接数据库 指定编码utf8
conn = MySQLdb.connect(host="172.25.254.18",user="yzy_data",passwd="pass",db="yzy_data",charset="utf8")
cursor = conn.cursor()

# 执行插入数据
sql = "insert into `test`(title,uid,purl) values(%s,%s,%s)"
param = ("测试插入","123321","http://pan.baidu.com/xxx")
n = cursor.execute(sql,param)
print "insert",n

cursor.close()

我这里是用的是MyISAM表引擎,所以并不需要插入后conn.commit()来提交才能插入数据。像Innodb这类支持事务的表都需要。

参考资料

关注公众号 尹安灿

部署Linux+Apache+nginx+MySQL+phpmyadmin。平时部署还是略显麻烦,尤其用于非生产环境的话,感觉好浪费体力。之前也一直想写个类似的脚本,一直懒得真正动手付诸实践。偶然遇见这个工具,感觉好方便。能满足需要。

https://lnmp.org/

关注公众号 尹安灿

用python需要用到mysql,遂想安装一个MySQL-Python.但是遇到如下错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
➜  ~ git:(master) ✗ sudo easy_install MySQL-python
[sudo] password for phan:
Searching for MySQL-python
Reading https://pypi.python.org/simple/MySQL-python/
Best match: MySQL-python 1.2.5
Downloading https://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c
Processing MySQL-python-1.2.5.zip
Writing /tmp/easy_install-oRVY0O/MySQL-python-1.2.5/setup.cfg
Running MySQL-python-1.2.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-oRVY0O/MySQL-python-1.2.5/egg-dist-tmp-tj3z87
sh: 1: mysql_config: not found
Traceback (most recent call last):
File "/usr/bin/easy_install", line 9, in <module>
load_entry_point('setuptools==20.7.0', 'console_scripts', 'easy_install')()
File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 2293, in main
distclass=DistributionWithoutHelpCommands, **kw
File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 414, in run
self.easy_install(spec, not self.no_deps)
File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 663, in easy_install
return self.install_item(spec, dist.location, tmpdir, deps)
File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 693, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 873, in install_eggs
return self.build_and_install(setup_script, setup_base)
File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1101, in build_and_install
self.run_setup(setup_script, setup_base, args)
File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1087, in run_setup
run_setup(setup_script, args)
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 246, in run_setup
raise
File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 195, in setup_context
yield
File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 166, in save_modules
saved_exc.resume()
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 141, in resume
six.reraise(type, exc, self._tb)
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 154, in save_modules
yield saved
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 195, in setup_context
yield
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 243, in run_setup
DirectorySandbox(setup_dir).run(runner)
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 273, in run
return func()
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 242, in runner
_execfile(setup_script, ns)
File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 46, in _execfile
exec(code, globals, locals)
File "/tmp/easy_install-oRVY0O/MySQL-python-1.2.5/setup.py", line 17, in <module>
File "/tmp/easy_install-oRVY0O/MySQL-python-1.2.5/setup_posix.py", line 43, in get_config
File "/tmp/easy_install-oRVY0O/MySQL-python-1.2.5/setup_posix.py", line 25, in mysql_config
EnvironmentError: mysql_config not found

度娘后,安装了libmysqlclient-dev解决

1
2
➜  ~ git:(master) ✗ sudo apt-get install libmysqlclient-dev

安装MySQL-python 搞定

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
➜  ~ git:(master) ✗ sudo easy_install MySQL-python         
Searching for MySQL-python
Reading https://pypi.python.org/simple/MySQL-python/
Best match: MySQL-python 1.2.5
Downloading https://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c
Processing MySQL-python-1.2.5.zip
Writing /tmp/easy_install-RxRikL/MySQL-python-1.2.5/setup.cfg
Running MySQL-python-1.2.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-RxRikL/MySQL-python-1.2.5/egg-dist-tmp-oH_bfi
zip_safe flag not set; analyzing archive contents...
Moving MySQL_python-1.2.5-py2.7-linux-x86_64.egg to /usr/local/lib/python2.7/dist-packages
Adding MySQL-python 1.2.5 to easy-install.pth file

Installed /usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg
Processing dependencies for MySQL-python
Finished processing dependencies for MySQL-python

关注公众号 尹安灿

前言

获取内容,比较纠结是用BeautifulSoup还是直接用正则匹配好。BeautifulSoup简单清晰,但是不够灵活。
正则则相反。

正文

信息位置的分析

像网盘,我们要提取的信息主要有共享者ID、资源名、网盘URL、资源大小、创建时间等等。搞清楚这些信息的位置,不是本文的重点,所以这里假设已经清楚了信息的位置,然后提取就行了。用共享者ID、资源名、网盘URL做个示范。

举个栗子,比如莽荒纪.zip的资源,URL是:http://www.sobaidupan.com/file-106010793.html从HTML中我们可以获得如下信息:

2082813876是sobaidupan.com的站内ID,也是百度云盘的用户ID。这就好办了。
但是资源的URL还要进一步加载http://sbdp.baidudaquan.com/down.asp?id=16166237&token=301efbbe2c138d150b41b5813a3d4077才能知道。
源码如下:

1
2
3
4
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<div style="margin:0 auto;margin-top:10%;width:600px;border: 1px solid #ff0000;line-height:30px;padding:10px 10px 10px 10px; ">提示:亲,正在为您跳转,请稍等2秒.....
<meta http-equiv='refresh' content='2;URL=http://pan.baidu.com/share/link?shareid=3994307345&uk=2755655514&fid=45639734040097'></div>

源码里的http://pan.baidu.com/share/link?shareid=3994307345&uk=2755655514&fid=45639734040097正是我们要的资源。

也就是说,要提取莽荒纪的资源名称,至少得加载两次URL,才能将信息提取全。

  • 第一次加载:http://www.sobaidupan.com/user-2082813876-1.html
    得到资源名、共享者ID和网盘的站内地址http://sbdp.baidudaquan.com/down.asp?id=106010793&token=c4e0d8de4bf94fe0d86a6b4f675fe176

  • 第二次加载: http://sbdp.baidudaquan.com/down.asp?id=106010793&token=c4e0d8de4bf94fe0d86a6b4f675fe176提取出网盘的真实地址。

提取信息

获取网站源码

上一篇日志提到如何提取源码。我把它放到一个叫yzyPublic.py文件里。所以等下得先导入这个文件再使用。

1
2
3
4
5
import yzyPublic

res = yzyPublic.get_web_source('http://www.sobaidupan.com/file-106010793.html')
print res

res内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<!DOCTYPE html>
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
<meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />

<title>莽荒纪.zip_zgh*****1617_百度云盘下载 - 搜百度盘</title>
<meta name="keywords" content="莽荒纪.zip" />
<meta name="description" content="小说/修真/莽荒纪.zip" />
<style type="text/css">
<!--
.f_color {
color: #FFFFFF;
font-weight: bold;
}
-->
</style>
</head>
<body>
<div class="headtop">
<div class="headtop_f"><B>搜百度盘(SoBaiduPan.com)</B>&nbsp;是基于百度云搜索,最大的百度云盘资源搜索中心,千万级大数据量,让您一网打尽所有的百度网盘资源.</div>
</div>
<div class="site_head w c">
<div class="sitelogo"><a href="/"><img src="image/logo.gif" border="0" title="SoBaiduPan.com"></a></div>
<div class="top_allsite" id="top_allsite"><ul>
<script type="text/javascript" src="top_txtad.asp"></script>
</ul></div>
</div>
<div class="menu w c">
<ul>
<li><a href="http://www.sobaidupan.com">首 页</a></li>
<li><a href="list-1-1.html">最新资源</a></li>
<li><a href="zhuan-1-1.html">影视目录</a></li>
<li><a href="zhuan-2-1.html">小说目录</a></li>
<li><a href="list-28-1.html">影视资源</a></li>
<li><a href="list-30-1.html">动漫资源</a></li>
<li><a href="list-29-1.html">小说资源</a></li>
<li><a href="zhuan-3-1.html">综合资源</a></li>
<li><a href="http://soft.sobaidupan.com" target="_blank" title="百度云下载器">云下载器</a></li>
<li><a href="m.asp" title="移动端访问">手机专版</a></li>
<li><a href="http://weipan.sobaidupan.com" title="新浪微盘资源搜索" target="_blank">新浪微盘</a></li>
<li><a href="about.asp?id=2" title="在线发布共享资源">发布资源</a></li>
<li><a href="http://bbs.sobaidupan.com" title="建议留言" target="_blank"><font color="#FFFF00">建议留言</font></a></li>
</ul>
</div>

<div class="smenu c">
<div class="smenu_nav">
<a href="list-3-1.html">torrent</a><a href="list-5-1.html">rmvb</a><a href="list-4-1.html">mp4</a><a href="list-7-1.html">mp3</a><a href="list-9-1.html">avi</a><a href="list-8-1.html">epub</a><a href="list-10-1.html">mkv</a><a href="list-11-1.html">flv</a><a href="list-12-1.html">pdf</a><a href="list-13-1.html">pps</a><a href="list-15-1.html">psd</a><a href="list-16-1.html">iso</a><a href="list-17-1.html">ghost</a><a href="list-19-1.html">exe</a><a href="list-20-1.html">txt</a><a href="list-21-1.html">apk</a><a href="list-22-1.html">ipa</a><a href="list-24-1.html">wps</a><a href="list-25-1.html">rtf</a><a href="list-26-1.html">vob</a><a href="list-13-1.html">ppt/pptx</a><a href="list-27-1.html">xls/xlsx</a><a href="list-14-1.html">doc/docx</a><a href="list-18-1.html">rar/zip</a>
</div>
</div>

<div class="search w c">
<table width="100%" height="90" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td>

<script type="text/javascript" src="ad/top1_580x90.js"></script>

</td>
<td>
<a href="adgo.asp?id=30" target="_blank"><img src="ad/ad2.jpg"></a>
</td>
</tr>
</table>
<div class="fgx"></div>
<form id="form1" name="form1" method="get" action="search.asp" ><img src="image/s.png" width="32" height="32" align="absmiddle">&nbsp;请您输入搜索内容:
<input name="wd" id="wd" placeholder="共108,789,857个资源,今日已更新2382..." type="text" size="30" value="" autocomplete="off" />
<input type="submit" id="Su" tabindex="2" value="网盘搜索" style="cursor:hand;">&nbsp;<img src="image/soso.gif" width="23" height="21" align="absmiddle"><a href="about.asp?id=1" target="_blank"><font color="red"><b>点击打赏本站</b></font>&nbsp;&nbsp;<a href="http://koubei.baidu.com/s/www.sobaidupan.com" target="_blank"><b>点击支持本站</b></a>&nbsp;<img src="image/new.gif" width="22" height="14" align="absmiddle">&nbsp;<a href="http://soft.sobaidupan.com" target="_blank"><font color="red"><b>百度云搜索器</b></font></a>
</form>
</div>
<script type="text/javascript" charset="gbk" src="opensug.js"></script>
<script type="text/javascript">
var txtObj = document.getElementById("alertSpan");
function show(str){
window.location.href="search.asp?r=0&wd="+encodeURIComponent(str);
}
var params = {
"XOffset":0,
"YOffset":0,
"width":204,
"fontColor":"#f70",
"fontColorHI":"#FFF",
"fontSize":"15px",
"fontFamily":"宋体",
"borderColor":"gray",
"bgcolorHI":"#03c",
"sugSubmit":false
};
BaiduSuggestion.bind("wd",params,show);
</script>

<div class="main w c">
<div class="art_bt_box w c"><ul><li><h1>莽荒纪.zip</h1></li></ul></div>
<div class="art_box">
<table border="0">
<tr>
<td width="250" valign="top" ><table width="250" border="0" cellpadding="0" cellspacing="1" bordercolor="#3E92CF" bgcolor="#3E92CF">
<tr>
<td width="250" height="119" bgcolor="#FFFFFF" ><div align="center"><a href="user-2082813876-1.html"><img src="http://himg.bdimg.com/sys/portrait/item/797c6b21.jpg" width="100" height="100" border="0"></a></div></td>
</tr>
<tr>
<td height="40" bgcolor="#FFFFFF" ><div align="center">用户名:zgh*****1617</div></td>
</tr>
<tr>
<td height="40" bgcolor="#FFFFFF" ><div align="center"><a href="user-2082813876-1.html"><img src="image/jrzy.gif" width="89" height="24" border="0"></a></div></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" >
<script src="ad/250x250.js" type="text/javascript"></script></div>
</td>
</tr>
<tr>
<td height="35" bgcolor="#3E92CF" >&nbsp;<span class="f_color">Ta 分享的其它资源:</span></td>
</tr>
<tr>
<td height="40" bgcolor="#FFFFFF">
<ul>
<li>&nbsp;<a href="file-1266183.html" title=网游——屠龙巫师.zip>网游——屠龙巫师.zip</a></li><li>&nbsp;<a href="file-1266216.html" title=网游-梦幻现实.zip>网游-梦幻现实.zip</a></li><li>&nbsp;<a href="file-1266234.html" title=神也玩转网游.zip>神也玩转网游.zip</a></li><li>&nbsp;<a href="file-1668670.html" title=魔兽英雄.zip>魔兽英雄.zip</a></li><li>&nbsp;<a href="file-1668832.html" title=阿亚罗克年代记.zip>阿亚罗克年代记.zip</a></li><li>&nbsp;<a href="file-1668883.html" title=重生之福星道士.zip>重生之福星道士.zip</a></li><li>&nbsp;<a href="file-1668930.html" title=重生之极限风流.zip>重生之极限风流.zip</a></li><li>&nbsp;<a href="file-1669255.html" title=英雄无敌之大航海时代.zip>英雄无敌之大航海时代.zip</a></li><li>&nbsp;<a href="file-1674467.html" title=网游之霸世神偷.zip>网游之霸世神偷.zip</a></li><li>&nbsp;<a href="file-2013963.html" title=霸王怒.zip>霸王怒.zip</a></li>
</ul>
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF" >
<script src="ad/250x250-2.js" type="text/javascript"></script></td>
</tr>
<tr>
<td height="35" bgcolor="#3E92CF" >&nbsp;<span class="f_color">其它网友正在下载的资源:</span></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" >
<ul>
<li>&nbsp;<a href="file-830.html" title=橄榄油 - 副本5.psd>橄榄油 - 副本5.psd</a></li><li>&nbsp;<a href="file-829.html" title=百度云管家 v4.8.0 绿色版 i2i2.cn.rar>百度云管家 v4.8.0 绿色版 i2i2.cn.rar</a></li><li>&nbsp;<a href="file-828.html" title=百度云管家 v4.8.0 单文件版 i2i2.cn.rar>百度云管家 v4.8.0 单文件版 i2i2.cn.rar</a></li><li>&nbsp;<a href="file-827.html" title=第1天上午.5.mp3>第1天上午.5.mp3</a></li><li>&nbsp;<a href="file-826.html" title=第2天下午.8.mp3>第2天下午.8.mp3</a></li><li>&nbsp;<a href="file-825.html" title=第2天上午.7.mp3>第2天上午.7.mp3</a></li><li>&nbsp;<a href="file-824.html" title=第1天下午.5.mp3>第1天下午.5.mp3</a></li><li>&nbsp;<a href="file-823.html" title=第1天上午.4.mp3>第1天上午.4.mp3</a></li><li>&nbsp;<a href="file-822.html" title=第2天下午.6.mp3>第2天下午.6.mp3</a></li><li>&nbsp;<a href="file-821.html" title=第1天下午.7.mp3>第1天下午.7.mp3</a></li>
</ul>
</td>
</tr>
</table>

</td>
<td height="61" align="left" valign="top" >
<table width="100%" border="0" align="left" cellpadding="0" cellspacing="0" bordercolor="#3E92CF" bgcolor="#3E92CF">
<tr>
<td bgcolor="#FFFFFF" >
<script type='text/javascript' src='http://m1.sobaidupan.com/fr3a1ec292ffc2f63fdb146392acb024e057e3d4002ef230ec51322bda.js'></script></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" ><div class="fgx"></div></td>
</tr>
<tr>
<td style="line-height: 30px" bgcolor="#FFFFFF" ><div align="left">&nbsp;<B>资源名称:</B>莽荒纪.zip</div></td>
</tr>
<tr>
<td style="line-height: 30px" bgcolor="#FFFFFF" ><div align="left">&nbsp;<B>资源类别:</B>小说/修真</div></td>
</tr>
<tr>
<td style="line-height: 30px" bgcolor="#FFFFFF" ><div align="left">&nbsp;<B>资源大小:</B>3.83 MB&nbsp;<b>资料扩展名:</b>.zip&nbsp;<b>访问/下载次数</b>:10/9&nbsp;<b>分享日期:</b>2016/9/5 11:13:00</div></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" ><div class="fgx"></div></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" >
<table width="100%" border="0" align="left">
<tr>
<td width="155">

<div align="center">
<a href="http://sbdp.baidudaquan.com/down.asp?id=106010793&token=c4e0d8de4bf94fe0d86a6b4f675fe176" title="莽荒纪.zip -百度网盘下载" target="_blank"><img src="image/wpdown.gif" width="137" height="34" border="0"></a></div></td>
<td width="152" bgcolor="#FFFFFF" ><div align="center"><a href="#" onclick="javascript:alert('违法信息举报信箱:sobaidupan@126.com')"><img src="image/zaixjb.gif" width="137" height="34" border="0" title="举报资源" style="cursor:pointer" id="police" ></a></div></td>
<td width="497" bgcolor="#FFFFFF" > <div class="bdsharebuttonbox"><a href="#" class="bds_more" data-cmd="more">分享到:</a><a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间">QQ空间</a><a href="#" class="bds_tieba" data-cmd="tieba" title="分享到百度贴吧">百度贴吧</a><a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信">微信</a><a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博">新浪微博</a><a href="#" class="bds_douban" data-cmd="douban" title="分享到豆瓣网">豆瓣网</a></div>

</td>
</tr>
</table></td>
</tr>

<tr>
<td bgcolor="#FFFFFF" ><div class="fgx"></div>
<script src="ad/728x90_2.js" type="text/javascript"></script>
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF" >
<div id="hm_t_97521"></div></td>
</tr>

<tr>
<td bgcolor="#FFFFFF" ><div class="fgx"></div><div align="left">
<script src="ad/336x280.js" type="text/javascript"></script>
</div></td>
</tr>
<tr>
<td height="35" bgcolor="#3E92CF" >&nbsp;<span class="f_color">相关资源:</span></td>
</tr>
<tr>
<td height="40" bgcolor="#FFFFFF" >
<ul>
<li>&nbsp;<a href="file-12334474.html" title=仙符问道.zip>仙符问道.zip</a></li><li>&nbsp;<a href="file-12335167.html" title=随身副本闯仙界.zip>随身副本闯仙界.zip</a></li><li>&nbsp;<a href="file-12335453.html" title=齐宇问道.zip>齐宇问道.zip</a></li><li>&nbsp;<a href="file-12335876.html" title=猫行天下.zip>猫行天下.zip</a></li><li>&nbsp;<a href="file-12336124.html" title=极品修真邪少.zip>极品修真邪少.zip</a></li><li>&nbsp;<a href="file-12424570.html" title=极品丹师.zip>极品丹师.zip</a></li><li>&nbsp;<a href="file-12744895.html" title=重生之唯我独仙.zip>重生之唯我独仙.zip</a></li><li>&nbsp;<a href="file-14281154.html" title=仙缘五行.zip>仙缘五行.zip</a></li><li>&nbsp;<a href="file-15903276.html" title=与狐仙双修的日子.zip>与狐仙双修的日子.zip</a></li><li>&nbsp;<a href="file-15903375.html" title=修真之位面交易系统.zip>修真之位面交易系统.zip</a></li><li>&nbsp;<a href="file-15903925.html" title=拜师八戒.zip>拜师八戒.zip</a></li><li>&nbsp;<a href="file-15904006.html" title=重生在白蛇的世界里.zip>重生在白蛇的世界里.zip</a></li><li>&nbsp;<a href="file-15904154.html" title=巫也是道.zip>巫也是道.zip</a></li><li>&nbsp;<a href="file-15979622.html" title=僵尸问道.zip>僵尸问道.zip</a></li><li>&nbsp;<a href="file-16005591.html" title=大地之皇.zip>大地之皇.zip</a></li><li>&nbsp;<a href="file-16484435.html" title=猪八戒重生记.zip>猪八戒重生记.zip</a></li><li>&nbsp;<a href="file-16484613.html" title=至神传说.zip>至神传说.zip</a></li><li>&nbsp;<a href="file-16484713.html" title=星空战神.zip>星空战神.zip</a></li><li>&nbsp;<a href="file-16484798.html" title=现代封神榜.zip>现代封神榜.zip</a></li><li>&nbsp;<a href="file-16735997.html" title=仙侠世界之天才掌门.zip>仙侠世界之天才掌门.zip</a></li><li>&nbsp;<a href="file-16888626.html" title=物理高材修仙记.zip>物理高材修仙记.zip</a></li><li>&nbsp;<a href="file-16889125.html" title=灵枢.zip>灵枢.zip</a></li><li>&nbsp;<a href="file-17136845.html" title=极品仙君.zip>极品仙君.zip</a></li><li>&nbsp;<a href="file-17175592.html" title=将修仙进行到底.zip>将修仙进行到底.zip</a></li><li>&nbsp;<a href="file-17175765.html" title=合成修仙传.zip>合成修仙传.zip</a></li><li>&nbsp;<a href="file-17257619.html" title=我做许仙的日子.zip>我做许仙的日子.zip</a></li><li>&nbsp;<a href="file-17349180.html" title=少年武仙在都市.zip>少年武仙在都市.zip</a></li><li>&nbsp;<a href="file-17349336.html" title=超级修仙之旅.zip>超级修仙之旅.zip</a></li><li>&nbsp;<a href="file-17349557.html" title=娇美仙妻爱上我.zip>娇美仙妻爱上我.zip</a></li><li>&nbsp;<a href="file-18057326.html" title=极品仙商.zip>极品仙商.zip</a></li>
</ul></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" >
<div class="fgx"></div>
<!-- UJian Button BEGIN -->
<div class="ujian-hook"></div>
<script type="text/javascript">var ujian_config = {num:16,target:1,picSize:72,textHeight:45,hoverTextColor:'#FA1B02'};</script>
<script type="text/javascript" src="http://v1.ujian.cc/code/ujian.js?uid=2087333"></script>
<a href="http://www.ujian.cc" style="border:0;"><img src="http://img.ujian.cc/pixel.png" alt="友荐云推荐" style="border:0;padding:0;margin:0;" /></a>
<!-- UJian Button END -->
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF" >
<div class="fgx"></div>

</td>
</tr>
<tr>
<td height="40" bgcolor="#3E92CF" >&nbsp;<span class="f_color">相关说明:</span></td>
</tr>
<tr>
<td height="40" bgcolor="#FFFFFF" ><div class="art_foot">莽荒纪.zip为搜百度盘收集整理的结果,下载地址直接跳转到百度网盘进行下载,该文件的安全性和完整性需要您自行判断。感谢您对本站的支持.</div> </td>
</tr>
<tr>
<td height="80" bgcolor="#FFFFFF" >
&nbsp;上一个:<a href="file-106010792.html" title="netplan.zip">netplan.zip</a>
<div class="fgx"></div>
&nbsp;下一个:<a href="file-106010794.html" title="斗战西游.zip">斗战西游.zip</a> </td>
</tr>

</table></td>
<td width="200" align="left" valign="top" >
<script src="ad/200x200.js" type="text/javascript"></script>

<div class="art_left_bt"><img src="image/hot.gif" width="22" height="11">&nbsp;您可能需要的资源:</div>

<ul>
<li>&nbsp;<a href="file-23821718.html" title=重生之婚后试爱.txt>重生之婚后试爱.txt</a></li><li>&nbsp;<a href="file-23827473.html" title=时光,浓淡相宜.txt>时光,浓淡相宜.txt</a></li><li>&nbsp;<a href="file-25264047.html" title=[书包网]亲爱的爱情(重生演艺圈).txt>[书包网]亲爱的爱情(重生演艺圈).txt</a></li><li>&nbsp;<a href="file-25650524.html" title=[古装言情]《二货娘子》作者:雾矢翊(晋江VIP2014-03-17完结)金牌高积分.txt>[古装言情]《二货娘子》作者:雾矢翊(晋江VIP2014-03-17完结)金牌高积分.txt</a></li><li>&nbsp;<a href="file-25651309.html" title=系统之宠妃.txt>系统之宠妃.txt</a></li><li>&nbsp;<a href="file-25651440.html" title=后宫翻身记(重生) .txt>后宫翻身记(重生) .txt</a></li><li>&nbsp;<a href="file-29456136.html" title=重生之汤圆儿.txt>重生之汤圆儿.txt</a></li><li>&nbsp;<a href="file-29456254.html" title=《重生之换我疼你》作者:森中一小妖.txt>《重生之换我疼你》作者:森中一小妖.txt</a></li><li>&nbsp;<a href="file-29717792.html" title=《宠妃》作者:月非娆.txt>《宠妃》作者:月非娆.txt</a></li><li>&nbsp;<a href="file-30877984.html" title=[网游]舍我娶谁.txt>[网游]舍我娶谁.txt</a></li>
</ul>
<script src="ad/160x600.js" type="text/javascript"></script>
</td>
</tr>

</table>
</div>
</div>

<script charset='gbk' src='http://p.tanx.com/ex?i=mm_113468001_12740314_57802967'></script>
<div class="cl"></div>
<div class="fgx"></div>
<div class="foot">
<p><img src="image/wj.png" width="36" height="43" align="absmiddle">&nbsp;&nbsp;搜百度盘(<a href="http://www.sobaidupan.com" title="搜百度盘">www.sobaidupan.com</a>&nbsp;2015-2018 All Rights Reserved&nbsp;<a href="zhaoshang.asp" title="广告合作及投放">广告合作</a>&nbsp;<a href="about.asp" title="关于本站">关于本站</a> &nbsp;QQ群:<a href="http://jq.qq.com/?_wv=1027&k=a2uzxT" target="_blank">385379281</a></p>
<p>本站仅提供百度网盘资源搜索和百度网盘资源下载的网站,本站只抓取百度网盘的链接而不保存任何资源. <script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "//hm.baidu.com/hm.js?f9d133598d63eabee77f59430aefa2ab";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
<script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1254604262'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s11.cnzz.com/stat.php%3Fid%3D1254604262' type='text/javascript'%3E%3C/script%3E"));</script> <a href="setxml.asp">sitemap.xml</a>
</p>
<p>本站所有资源均来自互联网,本站只负责技术收集和整理,均不承担任何法律责任,如有侵权违规等其它行为请联系我们. <img src="image/e.jpg" width="163" height="20" align="absmiddle"></p>
</div>
<br />

<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":["mshare","qzone","tsina","bdysc","weixin","tieba","douban","sqq","qq","hi","baidu","share189","fx","mail","copy"],"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{"bdSize":16}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
</body>
</html>
<script src="count.asp?id=106010793" type="text/javascript"></script>

提取用户ID、资源名、网盘URL

想了良久,还是决定使用BeautifulSoup和re正则共同完成信息的提取。
其实我个人是比较倾向于只使用正则提取,在以往我写的其它采集器基本都是用这个完成信息的提取。抱着学习的目的,加入了beautifulsoup。

导入相关的模块: BeautifulSoup和re

1
2
3
from bs4 import BeautifulSoup
import re

提取标题

标题这里都是存在h1标签里面。提取如下:

1
2
3
soup = BeautifulSoup(res,"html.parser")
print soup.h1.text

res是前面获取的网页源码’html.parser’解析,可以理解为让BeautifulSoup明白这个页面是什么语言写的。另外还有常用的lxml.

提取UID

uid这里的提取,我用了正则,觉得会简单点。BeautifulSoup的话,我还是会用到正则,后面我把两种方法都贴出来。

  • 方法1 直接正则匹配

    1
    2
    3
    uid = re.search('user-(\d*)-1\.html',res)
    print uid.group(1)

  • 方法2 BeautifulSoup配合正则找出符合的href属性

    1
    2
    3
    uid2 = soup.find(href=re.compile('user-\d*-1\.html'))['href']
    print uid2.split('-')[1]

提取网盘URL

这里需要先提取出站内下载的地址,加载源码,再提取出百度网盘地址。文章前面有提到过了。

提取站内下载URL

1
2
3
rurl = re.search('href="(http://sbdp\.baidudaquan\.com/down\.asp\?id=.+?)"',res)

print rurl.group(1)

提取百度网盘地址

1
2
3
4
dres = yzyPublic.get_web_source(rurl.group(1))
purl = re.search("URL=(http://pan\.baidu\.com/share/link\?shareid=.+?)'",dres)
print purl.group(1)

封装成函数提高代码复用

按自己习惯自己搞。不赘述。

参考资料

关注公众号 尹安灿

前言

过完年无聊,想学学Python,想了半天,从实用的角度出发,打算边学边做。想了半天,还是写一个采集器好点。
目标嘛,就是采集 www.sobaidupan.com 的内容入库。因为是初学,有很多不懂,所以一切从简,实现目的第一,性能第二。

正文

既然要采集,肯定得先获取网页源码。其中使用urllib和requests模块最多。而其中requests模块提供的api来看,友好度最高,所以打算采用requests。但是requests是一个第三方模块。所以

安装requests模块

pip install requests

获取网页源码

导入requests模块,调用get的方法。不清楚http的get、post、put、delete等方法的,度娘http协议了解。
简单来说,一般获取网页信息,绝大部分都是用的get,而提交信息,基本都是用post。我说是绝大部分。
下面就来一段代码演示如何获取www.baidu.com首页的源码。简直好用到哭。

获取源码

1
2
3
import requests
res = requests.get('http://www.baidu.com')
print res.text

结果如下:

1
2
3
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>ç™¾åº¦ä¸€ä¸‹ï¼Œä½ å°±çŸ¥é“</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>&copy;2017&nbsp;Baidu&nbsp;<a href=http://www.baidu.com/duty/>使用百度前必读</a>&nbsp; <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a>&nbsp;京ICP证030173号&nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>

获取源码并解码

源码是有了,但是中文变成了乱码。该网页用的是utf-8,所以还要指定编码名。这样程序才知道用什么编码来解码并展示出来。正确的解码才能获取到我们想要的内容。所以代码变成了下面的样子。

1
2
3
4
import requests
res = requests.get('http://www.baidu.com')
res.encoding='utf-8'
print res.text

结果如下:

1
2
3
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>&copy;2017&nbsp;Baidu&nbsp;<a href=http://www.baidu.com/duty/>使用百度前必读</a>&nbsp; <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a>&nbsp;京ICP证030173号&nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>

这下总算能看到中文了。

封装成一个函数

为了提高复用性,所以打算把它封装成一个函数,比如get_web_source,这样以后获取不同的url,和编码,将其作为参数传入就能正确获取源码了。所以我把它写成了这个样子。

1
2
3
4
5
6
7
8
9
10
11
import requests

# 定义函数
def get_web_source(url,encode="utf-8"):
res = requests.get(url)
res.encoding = encode
return res.text

# 测试函数 打印出源码,第二个参数我默认填的是utf8,所以我不写。如果是GBK、GB2313或者其它的再填第二个参数。
print get_web_source('http://www.baidu.com')

结果如下:

1
2
3
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>&copy;2017&nbsp;Baidu&nbsp;<a href=http://www.baidu.com/duty/>使用百度前必读</a>&nbsp; <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a>&nbsp;京ICP证030173号&nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>

结果正确,收工!

参考资料

关注公众号 尹安灿

$f(\sqrt{x}+1)=x+2\sqrt{x}$ 求 $f(x)$ 的解析式

  1. 换元法:设 $t=\sqrt{x}+1$ ,则 $x=(t-1)^2$ ,且 ( $x\geq1$ )$f(t)=(t-1)^2+2(t-1)=t^2-1$ $(t \geq 1)$$f(x)=x^2-1$ $( x\geq 1 )$

来源

Markdown 公式指导手册

Special Symbols

关注公众号 尹安灿

0%