标题: 求教:已写一bat檔利用wget抓出某网页原始檔
[打印本页]
作者: denis
时间: 2008-12-18 12:16
标题: 求教:已写一bat檔利用wget抓出某网页原始檔
求教:已写一bat檔利用wget抓出某网页原始檔于code.txt,但只要某”字符串”(如:所有的”yahoo”)填入于g.txt
该如编写?~谢谢?!!
@echo off
wget -q -O code.txt tw.dictionary.yahoo.com/
for /l %%i in (1,1,4) do echo %%i>nul
cls
title监控处理程序
::有问题的写法;请各先进帮忙修正谢谢
for /f "tokens=* delims=*" %%a in ('FINDSTR "yahoo" code.txt') do (echo %%a >>g.txt)
pause
作者: yishanju
时间: 2008-12-18 12:55
WGET 好像不能提交表单,
改用CURL 试试
CURL 功能上貌似更加强大
作者: denis
时间: 2008-12-18 13:06
我要问的重点不是wget的使用;而是在code.txt内已有该网页之原始檔存在,但为不规则排列
内有html卷标也有标点符号也有空格;但我只要将内文字符串所有的”yahoo”取出于g.txt;不知单用DOS批次作的到吗?谢谢!!
作者: HAT
时间: 2008-12-18 13:14
code.txt的内容贴出来
并指明你要提取哪些字符串
作者: denis
时间: 2008-12-18 13:35
code.txt的内容已上传
希望g.txt的内容为(有几个文字yahoo就印几行yahoo)如下:
yahoo
yahoo
yahoo
作者: denis
时间: 2008-12-18 13:41
http://upload.cn-dos.net/img/1200.rar
作者: clian76
时间: 2008-12-18 14:20
可以不用第三方工具的,用VBS直接取得网页源码或页面。再查找。用VBS看网页源码的代码搜索下坛子里有。
作者: denis
时间: 2008-12-18 16:26
我再把我的问题说明一遍好了
现在有txt里面如下
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">
<html>
<head>
<title>Yahoo!奇摩字典</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link href="http://l.yimg.com/tw.yimg.com/i/tw/dictionary/i7/dic.css?v=20071116a" rel="stylesheet" type="text/css">
</head>
<!-- SpaceID=0 robot -->
<!-- end header.inc -->
<body>
<div id="maincol">
<div id="yhtw_masthead">
<div class="mhlogo">
<a href="/"><img src="http://tw.yimg.com/i/tw/dictionary/masthead_logo.gif" alt="Yahoo!奇摩字典" /></a>
</div>
<div class="mhsch">
<form action="http://tw.rd.yahoo.com/referurl/srch/search/dictionary/*
http://tw.search.yahoo.com/search" target="_top">
<input type="hidden" name="fr" value="ush_dict">
<input type="hidden" name="ei" value="UTF-8">
<p>
<label class="t"><input type="text" name="p" /></label>
<label class="s"><input type="submit" value="搜寻网页" /></label>
</p>
<div>
<a href="/">服务首页</a><b>|</b><a href="http://tw.help.cc.yahoo.com/cp_info.html?product=dictionary">服务说明等等.
我想生成一个txt如下(将上述内码里有”yahoo”取出填入)
yahoo
yahoo
yahoo
等.
老大帮帮忙
作者: ily2013
时间: 2008-12-18 17:33
区分大小写吗?不太明白生成这样一个文件有什么用,想知道^_^
sed "s/yahoo/\n&\n/g" test.txt|sed -n "/yahoo/p"
希望我理解的没错
作者: dwj61909
时间: 2008-12-18 18:23
来个gawk的
gawk "/yahoo|Yahoo/ {printf \"yahoo\r\n\"}" code.txt>g.txt
[
Last edited by dwj61909 on 2008-12-18 at 18:25 ]
作者: denis
时间: 2008-12-18 19:53
呀!顿时开悟不少~
其实只是把yahoo的网页拿来当测试用….
真正目的为要监控一系统网站;若原始码内有出现(Tier1)~(Ter4)就代表有异常…就必须对该系统作处理及通知负责人
若通知后该网页则会有”已通知”字符串出现;但同一时间又有可能其它server出现异常那上述(Tier1)~(Ter4)字符串又会出现
故以字符串去做判别的话:
状况1:”Tier*” exist && “已通知” !exist echo alert(“msg”)
状况2: num(”Tier” exist) = num(“已通知” exist) do nothing
状况3: num(”Tier” exist) > num(“已通知” exist) alert(“msg”)
状况3: ”Tier*” !exist && “已通知” !exist do nothing
将上述状况写成一bat run at every 2 minute….
感谢各位大大先进帮忙;获益良多….
作者: ngd
时间: 2008-12-19 11:55
Quote: |
Originally posted by yishanju at 2008-12-18 12:55:
WGET 好像不能提交表单,
改用CURL 试试
CURL 功能上貌似更加强大 |
|
wget和curl都能提交表单
记得保存cookie
以登录cn-dos为例:
curl -c cookie.txt -d "username=ngd&password=密码"
http://www.cn-dos.net/forum/logging.php?action=login
wget --save-cookies=cookie.txt --post-data="username=ngd&password=密码"
http://www.cn-dos.net/forum/logging.php?action=login
作者: denis
时间: 2008-12-22 09:42
Quote: |
Originally posted by dwj61909 at 2008-12-18 06:23 PM:
来个gawk的
gawk "/yahoo|Yahoo/ {printf \"yahoo\r\n\"}" code.txt>g.txt [ Last edited by dwj61909 on 2008-12-18 at 18:25 ] |
|
上述可改成gawk "/已通知/ {printf \"yahoo\r\n\"}" code.txt>g.txt吗?
即pattern型式可以为中文字符串吗?
作者: dxka8cww
时间: 2008-12-22 09:47
学习了`哈哈