shell 抓取网页解析网页 自动读取poj测试数据——V2生成 pku poj acm编程模版
2013-10-14 22:55
399 查看
#!/bin/bash ################################# #Copyright:free #Author:wangkai #Date:2013-10-13 #Description:从poj抓取网页,将网页中的输入数据自动 #保存到题号开头的文件中。网页特点是http://poj.org/problem?id=1001 #1001表示题号 #shell抓取网页,解析内容,允许测试环境ubuntu 12.04 #传入的第一个参数为题号 ################################# send=`date '+%Y-%m-%d %H:%M:%S'` i=$1; #传入的第一个参数为题号 id=$i; dir='Dropbox/#acm_linux/poj_code/data/' dircode='Dropbox/#acm_linux/poj_code/' if [ ! -d "$dir" ]; then mkdir $dir fi touch ${dir}file_html cppname=${dircode}poj_${id}.cpp if [ ! -d "$cppname" ]; then touch $cppname; echo '/************************************************ #Copyright:free #Author:wangkai #Date:2013-10-13 #Description:从poj抓取网页,将网页中的输入数据自动 #FileName:poj_'${id}'.cpp #Date:'${send}' ************************************************/ int main(){ freopen("poj_'${id}'.cpp","r",stdin) return 1; } '>$cppname fi #for((i=1010;i<=1020;i++));do file_loc=${dir}${i}; pre_html='http://poj.org/problem?id='; html=${pre_html}${id} wget $html -O ${dir}/file_html FILE_CONTENT=`cat ${dir}/file_html` FILE_CONTENT=${FILE_CONTENT#*<p class=\"pst\">Sample Input</p><pre class=\"sio\">} # 去除前缀 FILE_CONTENT=${FILE_CONTENT%%</pre><p class=\"pst\">Sample Output</p><pre class=\"sio\">*} # 去除后缀 echo $FILE_CONTENT >$file_loc # dos2unix $id # 出现则安装dos2unix使用此命令进行转化 #done
更多关于我的信息请访问http://www.linkedin.com/in/wangkaikai
相关文章推荐
- 更改IP的Shell脚本
- Shell
- 8 个使用的Linux shell 命令
- Using CSharp (C#) code in Powershell scripts
- shell date 命令详解--总结
- Android 手机执行shell命令
- 关于/bin/bash^M: bad interpreter: 没有那个文件或目录的错误
- WinCE6.0自启动Shell、应用程序、无Window Explorer界面
- shell 特殊变量
- Android adb shell 无法启动:insufficient permissions for device
- shellcode执行发生段错误问题的解决
- tomcat启动shell编写
- shell中使用while循环ssh的注意事…
- Shell脚本批量修改图片尺寸
- shell判断主机是否存活
- shell编程之条件测试
- linux在shell中获取时间
- 直接插入排序、折半插入排序、shell插入排序
- shell特性
- Bash中的通配符