你见过哪些令你瞠目结舌的爬虫技巧?
第一条:you-get(Releases · soimort/you-get · GitHub,这里面有各种发布版本)。什么,你不知道?想爬取视频网站的视频和图片分享网站的图片,是不是就得造个轮子写个爬虫?No,你只需要:
❯ pip3 install you-get
能干什么呢?我提供几个例子:
1. 下载优酷视频
❯ you-get http://v.youku.com/v_show/id_XMTc1MDQwODMxNg\=\=.html
site: 优酷 (Youku)
title: 麻雀 51
stream:
- format: hd2
container: flv
video-profile: 超清
size: 552.9 MiB (579718488 bytes) # download-with: you-get --format=hd2 [URL]
Downloading 麻雀 51.flv ...
100% (552.9/552.9MB) ├██████████████████████████████████████████████████████████████████████████┤[16/16] 9 MB/s
Merging video parts... Merged into 麻雀 51.mp4
评论区 @xavierskip 提到可以使用-p观看无广告的优酷视频!我在Mac上使用的是mplayer
,安装和使用方法如下:
❯ brew install mplayer ❯ you-get -p /usr/local/Cellar/mplayer/1.3.0/bin/mplayer http://v.youku.com/v_show/id_XMTc1MDQwODMxNg==.html
这样就可以使用本地播放器播放了
2. B站
❯ you-get http://www.bilibili.com/video/av6543659/
Site: bilibili.com
Title: 【张继科】论张继科的CP是如何被国胖队手撕的
Type: Flash video (video/x-flv)
Size: 28.2 MiB (29567551 Bytes)
Downloading 【张继科】论张继科的CP是如何被国胖队手撕的.flv ...
100% ( 28.2/ 28.2MB) ├████████████████████████████████████████████████████████████████████████████┤[1/1] 7 MB/s
Downloading 【张继科】论张继科的CP是如何被国胖队手撕的.cmt.xml ...
3. 网易云音乐
❯ you-get http://music.163.com/\#/song\?id\=424262521
Site: 163.com
Title: 5. Rolling in the deep
Type: MP3 (audio/mpeg)
Size: 5.86 MiB (6144044 Bytes)
Downloading 5. Rolling in the deep.mp3 ...
100% ( 5.9/ 5.9MB) ├████████████████████████████████████████████████████████████████████████████┤[1/1] 16 MB/s
Saving 5. Rolling in the deep.lrc ...Done.
4. 花瓣画板
❯ you-get http://huaban.com/boards/27965679/
Site: 花瓣 (Huaban)
Title: 黑板画
Type: JPEG Image (image/jpeg)
Size: inf MiB (inf Bytes)
Downloading 595209478.jpeg ...
0.0% ( 0.1/ infMB) ├────────────────────────────────────────────────────────────────────────────┤[1/1] 114 kB/s
Downloading 595209312.jpeg ...
0.0% ( 0.0/ infMB) ├────────────────────────────────────────────────────────────────────────────┤[1/1] 152 kB/s
Downloading 595209225.jpeg ...
0.0% ( 0.1/ infMB) ├────────────────────────────────────────────────────────────────────────────┤[1/1] 344 kB/s
Downloading 595209031.jpeg ...
0.0% ( 0.0/ infMB) ├────────────────────────────────────────────────────────────────────────────┤[1/1] 119 kB/s
Downloading 595208942.jpeg ...
0.0% ( 0.1/ infMB) ├────────────────────────────────────────────────────────────────────────────┤[1/1] 248 kB/s
.... 图片太多就展示到这里吧 (๑>◡<๑)
支持的网站太多,还是去GitHub - soimort/you-get: Dumb downloader that scrapes the web看吧,如果你有其他网站的需求,欢迎去PR添加支持,未来让其他同学也能受益。
还不快去用!!!
you-get的可扩展爬虫实现非常值得学习,相信给它贡献代码甚至读了它的源码都会对你的爬虫技术有所提高的。
第二条: 不要只看 Web 网站, 还有移动版、 App 和 H5, 它们的反爬虫措施一般比较少, 所有社交网站爬虫, 优先选择爬移动版。 这条大家好像都是直接忽略的... 忧伤
欢迎关注本人的微信公众号获取更多Python相关的内容(也可以直接搜索「Python之美」):
编辑于 2017-04-17 23:18