laomao127 发表于 2010-11-26 15:04:13

[已解决]获取帖子的名称和连接

本帖最后由 laomao127 于 2010-12-1 23:40 编辑



如图:获取 “如何获得网页中获得焦点元素的超链接? ”这个帖子的题目和连接 还有 点击和回复
在论坛上搜了一下 但是获取不成功,请高手帮忙。谢谢

答案:五、六、八 楼

laomao127 发表于 2010-11-26 16:13:57

斑竹高手不在吗?

afan 发表于 2010-11-26 16:33:37

分析源码,正则获取

laomao127 发表于 2010-11-26 16:55:03

回复 3# afan

我在论坛上也看过差不多相关的 网页分析的代码,但是总修改不成功,能帮忙写一下吗?简单点也可以 只要功能能实现就可以实现一个 其他的我比葫芦花瓢 可以吗?主要是一个都实现不了 ,麻烦斑竹了。

shenrenba 发表于 2010-11-26 17:27:50

代码中不完美的地方就是 $out 想写成一行 一直出错 不知怎么整合 谁来帮下
#include <INet.au3>
#include <Array.au3>
$source = _INetGetSource("http://www.autoitx.com/forum-4-1.html")
$sr = StringRegExp($source, '(?s)">([^<]*)</a>].+?href="([^"]*).+?([^><\v]*)</a>.+?<cite>.+?html">([^<]*)</a>.+?<em>([^<]*).+?<strong>([^<]*).+?<em>([^<]*).+?>([^<]*)</a></cite>', 3)
Local $out
$out = "帖子类型:"
$out = "帖子问题:"
$out = "提问者:"
$out = "最后回答者:"
$out = "回复数:"
$out = "查看数:"
$out = "发表时间:"
$out = "帖子地址:"
For $i = 0 To UBound($sr) - 1 Step 8
        $out = $sr[$i]
        $out = $sr[$i + 2]
        $out = $sr[$i + 3]
        $out = $sr[$i + 7]
        $out = $sr[$i + 5]
        $out = $sr[$i + 6]
        $out = $sr[$i + 4]
        $out = "http://www.autoitx.com/" & $sr[$i + 1]
Next
_ArrayDisplay($out)

yiruirui 发表于 2010-11-26 17:43:47

楼上可以借助这个UDF实现2维数组。Func _ArrayAdd2(ByRef $array1,$array2);_ReArrayAdd(目标数组,增加内容)
        If IsArray($array2) Then
                If UBound($Array2, 0) <> 1 Then Return SetError(2, 0, -1);增加内容不是一个一维数组
        Else
                Return SetError(1, 0, -1);返回错误代码1,增加的内容非数组
        EndIf
        If Not IsArray($array1) Then Return SetError(3, 0, -1);返回错误代码3,目标数组非数组
        $One_Dimen=UBound($array2);取一维数组数量
        $Many_Dimen=UBound($array1,0);取二维数组维数
        Local $Many_Dimen_Line=UBound($array1,1);取二维数组行数
        $Many_Dimen_Col=UBound($array1,2);取二维数组列数
        If $Many_Dimen<>2 Then Return SetError(4,0,-1);返回错误代码4,目标数组非二维数组
        If $One_Dimen<$Many_Dimen_Col Or $One_Dimen>$Many_Dimen_Col Then
                ReDim $array2[$Many_Dimen_Col]
        EndIf
        ReDim $array1[$Many_Dimen_Line+1][$Many_Dimen_Col]
        For $add_i=0 To $Many_Dimen_Col-1
      $array1[$Many_Dimen_Line][$add_i]=$array2[$add_i]               
        Next
        Return $Many_Dimen_Line
       
EndFunc

afan 发表于 2010-11-26 21:23:23

不要拿咱们论坛做实验吧,现在访问已经够慢了~ {:face (113):}

afan 发表于 2010-11-26 21:26:43

以前写的例子,不记得哪个帖子了#include <INet.au3>
#include <Array.au3>

$sUrl = 'http://www.excelpx.com/index.asp?boardid=38'
Tooltip('正在获取源码,请稍候……')
$str = _INetGetSource($sUrl)
$str = StringRegExpReplace($str, 'amp;|&quot;', '')
$sR = StringRegExp($str, '<a href=\"(.+?)\".+title=\"《(.+)》', 3)
If @error Then Exit MsgBox(0, 0, '未找到匹配~')
Dim $link, $x = 0
For $i = 0 To UBound($sR) - 1 Step 2
        $link[$x] = $sR[$i + 1]
        $link[$x] = 'http://www.excelpx.com/' & $sR[$i]
        $x += 1
Next
Tooltip('')
_ArrayDisplay($link, '标题及链接')

laomao127 发表于 2010-12-1 14:17:39

#include <INet.au3>
#include <Array.au3>

$sUrl = 'http://www.excelpx.com/index.asp?boardid=38'
Tooltip('正在获取源码,请稍候……')
$str = _INetGetSource($sUrl)
$str = StringRegExpReplace($str, 'amp;|&quot;', '')
$sR = StringRegExp($str, '<a href=\"(.+?)\".+title=\"《(.+)》', 3)
If @error Then Exit MsgBox(0, 0, '未找到匹配~')
Dim $link, $x = 0
For $i = 0 To UBound($sR) - 1 Step 2
      $link[$x] = $sR[$i + 1]
      $link[$x] = 'http://www.excelpx.com/' & $sR[$i]
      $x += 1
Next
Tooltip('')
_ArrayDisplay($link, '标题及链接')

afan 发表于 2010-12-1 14:20:34

“已经解决”改为“已解决”

rain 发表于 2010-12-1 14:25:08

不要拿咱们论坛做实验吧,现在访问已经够慢了~
afan 发表于 2010-11-26 21:23 http://www.autoitx.com/images/common/back.gif


    这句话很有喜感~~
页: [1]
查看完整版本: [已解决]获取帖子的名称和连接