---
title: "shell使用实践"
author: "winse"
date: "2013-03-07T00:02:45Z"
tags: []
categories: ["编程语言"]
slug: "shell"
draft: false
lastmod: "2013-03-07T00:03:38Z"
id: 1825164
url: "https://winse.iteye.com/blog/1825164"
---

通过shell来获取视频地址，简化生活，所以这个分类到编程之美下面。

 

这里讲的是使用shell获取163 ted视频下载地址。

 

效果如图：

 

![](http://dl.iteye.com/upload/attachment/0081/2502/46508462-fc71-32dc-aa7f-2258cda983f6.png)  
 

shell脚本如下：

 

```
#!/bin/sh

wget -qO- http://open.163.com/ted/ | iconv -f gbk -t utf-8 | awk '{if($0 ~ /<a href="http:\/\/v\.163\.com\/movie/ ){print}}' \
 | sed -n 's/.*<a href="\([^"]*\)".*/\1/p' \
 | while read url
do 
        echo $url;
        wget -qO- "$url" | iconv -f gbk -t utf-8 | awk '/appsrc: \047http:\/\//{if(match($0,/http:[^\047]*/))print substr($0,RSTART,RLENGTH);}' \
 | sed -e s/-list\.m3u8/.mp4/ -e s/movie/movieMP4/
done
```

 

“\\047” 表示单引号！

 

获取到mp4的列表之后，你想怎么弄就怎么弄了～～～

 

 

## 参考资料：

1、 awk怎么输入特殊字符\[ http://cn.mzcart.com/2012/07/130.html ]