7

用linux命令抓帖子(民间中医奇才.doc)

 2 years ago
source link: https://chegva.com/2845.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

用linux命令抓帖子(民间中医奇才.doc)

2018年3月31日 by anzhihe·0评论 · 1,855 人阅读 · 隐藏边栏 · 最后更新: 2018/12/3
  • 生产实践:

    一个朋友想在民间中医论坛下载一个帖子,但该帖子有1614页回帖,粘贴复制太麻烦了,在朋友圈求助。(原帖:http://www.ngotcm.com/forum/thread-50247-1-1.html)

  • 学习技巧:

    不会爬虫,想着就用wget、sed+软件来实现

  • 操作内容: 

1.该帖子回帖都是html静态页面,所以第一步使用wget把所有关于回帖的html页面全部下载下来,别的图片,js啥的都不需要

下载帖子:wget  -c -p -np -nd -nc -e robots=off -k --wait=2 --limit-rate=200K -i download.txt 

wget使用说明:

wget -r -c -p -np -nd -nc -e robots=off -k --wait=1 --limit-rate=200K -A "xxx-123*.html" 

wget -t 5 -Q 500m -nH -r -E -l inf -k -p -np 'http://www.w3school.com.cn/'
忽略 robots.txt,加上 -e robots=off
限速: –limit-rate=300k
-b 后台下载
限制下载速度及两次下载之间等待的时间
--wait=20 --limit-rate=20K
如果网站检测不到浏览器标识,会拒绝你的下载连接或者给你发送回一个空白网页。这个时候在 wget 后面加上 user-agent
 -U Mozilla
 -E //将所有text/html文档以.html扩展名保存

 -R index.html  : 不下载 index.html 文件

 -A jpg,png :下载指定名称或类型文件

wget使用参考:

2.将html文件夹打包发到windows系统上,用软件将html格式批量转换成txt格式,然后合并成一个txt文本

文本处理软件:TextForever.zip

3.使用sed过滤txt文件,然后粘贴到word上,批量替换掉一些没用的内容,就OK啦

sed -n  '/复制链接/,/高级模式/p' zy.txt  > zy1.txt

sed -i '/本帖最后/d' zy1.txt

sed -i '/1610/d' zy1.txt

sed -i '/高级模式/d' zy1.txt

sed -i  '/thread-50247-[[:digit:]]\{1,4\}-1.html/s%http://www.ngotcm.com/forum/thread-50247-[[:digit:]]\{1,4\}-1.html%%g' zy1.txt

4.OK完成,看了一下这篇帖子干货还是比较多的,正好在学中医基础,搞健身,收下看看

anzhihe安志合个人博客,版权所有丨 如未注明,均为原创 丨转载请注明转自:https://chegva.com/2845.html | ☆★★每天进步一点点,加油!★★☆

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK