pentiumcs 发表于 2010-4-4 12:11:07

查找网页内字符串,匹配后执行程序或快捷键

http://blog.sina.com.cn/guodegang

要求很简单,当这个博客的访问量到某值(这个可以自定义,如果能做到匹配多处更好,我只需要一处)时自动截图保存在某处

PS:要自动后台执行

PS2:如果有类似的软件可以达到这目的,麻烦说一下名字即可

l4ever 发表于 2010-4-4 12:20:18

发一段我写好的,给你参考
Func readcheck()
        $dxsz=IniReadSection("config.ini","对象设置")
        If not @error Then
        For $i = 1 To $dxsz
                Sleep(2000)
                ;名称$dxsz[$i]
                ;网址$dxsz[$i])
        $checkresult = checktext($dxsz[$i],$dxsz[$i])
                If $checkresult = "1" Then
                        Sleep(1000)
                ElseIf $checkresult = "0" Then
                        Writelog("错误","检测 "&$dxsz[$i]&" 页面内容不包含"""&$dxsz[$i]&"""")
                        fix()
                Else
                        Writelog("错误 | "&$checkresult,"检测 "&$dxsz[$i]&" 页面内容是否包含"""&$dxsz[$i]&"""时发生了未知错误.")
                        fix()
                EndIf
        Next
Else
                Writelog("错误","无法读取检测对象,请检查配置文件.")
                sleep(1000)
        EndIf
       
EndFunc

Func checktext($url,$text)
        SplashTextOn("", "正在检查页面内容,请稍等", 220, 35, -1, -1, 33, "ARIAL", 9)
        Sleep(1000)
        FileDelete(@TempDir&"\CheckText.txt")
        InetGet($url,@TempDir&"\CheckText.txt",1,0)
   $htmlcontent = FileRead(@TempDir&"\CheckText.txt")
       $htmltitle = StringInStr ($htmlcontent, $text ,0,1)
       If $htmltitle ="0" Then ;失败
               Return 0
       Else
               Return 1
       EndIf
EndFunc

l4ever 发表于 2010-4-4 12:20:44

config.ini

[对象设置]
关键词=网址

pentiumcs 发表于 2010-4-4 13:46:50

谢谢楼上...但是我是菜鸟,能不能指导一下?

1.这代码不需要修改关键字什么的吧?
2.config.ini里面怎么写? 最好有个例子

clshuai 发表于 2010-4-14 22:08:17

我写了一个比较笨的方法,楼主可以尝试#include <IE.au3>

$URL = "http://blog.sina.com.cn/guodegang"
$oIE = _IECreate($URL)

Sleep(10000)

$content = _IEBodyReadText($oIE)

$index1 = StringInStr($content,"博客访问:")

$index2 = StringInStr($content,"关注人气")

$str = StringMid($content,$index1+5,$index2 - $index1 - 5)

$str = StringReplace($str,",","")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $str = ' & $str & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

$AcessNum = Number($str)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $AcessNum = ' & $AcessNum & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

If $AcessNum > 18000000 Then
       
        _ScreenCapture_Capture(@MyDocumentsDir & "\image.jpg")
       
        MsgBox(0,"SaveImage","图片保存在:" & @MyDocumentsDir & "\image.jpg");
       
EndIf

_IEAction($oIE,"quit")
页: [1]
查看完整版本: 查找网页内字符串,匹配后执行程序或快捷键