ac5474012 发表于 2009-10-2 10:54:07

如何获取一个网页中的文本超链接的链接

这个网站 http://www.uname.cn/dic/wordlist.asp
我想获取这个文本超链接的链接

ac5474012 发表于 2009-10-2 11:44:32

为什么这样不管用?

#include <IE.au3>
$oIE = _IE_Example ("http://www.uname.cn/dic/wordlist.asp")
$oLinks = _IELinkGetCollection ($oIE)
$iNumLinks = @extended
MsgBox(0, "Link Info", $iNumLinks & " links found" & $oLinks)
For $oLink In $oLinks
    MsgBox(0, "Link Info", $oLink.href)
Next

ac5474012 发表于 2009-10-2 12:12:20

#include <IE.au3>
$oIE = _IE_Example ("http://www.uname.cn/dic/zidian.asp")
$oTable = _IETableGetCollection ($oIE, 1)
$aTableData = _IETableWriteToArray ($oTable)
MsgBox(0,"",$aTableData)
MsgBox(0,"",$aTableData)
MsgBox(0,"",$aTableData)
MsgBox(0,"",$aTableData)

怎么这样也不管用?

wxb2422 发表于 2009-10-2 12:12:32

本帖最后由 wxb2422 于 2009-10-2 12:18 编辑

#include <IE.au3>
$oIE = _IECreate ("http://www.uname.cn/dic/wordlist.asp",0,0,1,0)
$oLinks = _IELinkGetCollection ($oIE)
$i=0
For $oLink In $oLinks
        $i=$i+1
        MsgBox(0,"链接"&$i,$oLink.href ,1)
Next

这是获取全部链接,选择你自己想要的那个~
我也刚学。。说得不对请谅解

ac5474012 发表于 2009-10-2 13:29:49

本帖最后由 ac5474012 于 2009-10-2 13:36 编辑

4# wxb2422

可是问题在于我要取出这其中某一次的数值要怎么做呢?第72次。

ac5474012 发表于 2009-10-2 14:20:05

我用了这种办法,能不恩那个直接提取?$i = 0
For $oLink In $oLinks
        $i = $i + 1
        FileWriteLine("fasdf.txt", $i & "-" & $oLink.href)
        If $i = 75 Then
                $s = $oLink.href
        EndIf
;~         MsgBox(0,"链接"&$i,$oLink.href ,1)
Next
MsgBox(0, "", $s)全文#include <IE.au3>
#include <Constants.au3>
#include <Date.au3>
$oIE = _IECreate("http://www.uname.cn/dic/zidian.asp")
$a = _IEGetObjByName($oIE, "gb")
_IEFormElementSetValue($a, "国")
$oSubmit = _IEGetObjByName($oIE, "gb")
$b = _IEGetObjByName($oIE, "Submit")
_IEAction($b, "click")
_IELoadWait($oIE)
$oLinks = _IELinkGetCollection($oIE)
$i = 0
For $oLink In $oLinks
        $i = $i + 1
        FileWriteLine("fasdf.txt", $i & "-" & $oLink.href)
        If $i = 75 Then
                $s = $oLink.href
        EndIf
;~         MsgBox(0,"链接"&$i,$oLink.href ,1)
Next
MsgBox(0, "", $s)

sxd 发表于 2009-10-2 16:20:00

其实很多编程里很多东西 都是用的历遍

很多 find indexof 之类 都是封装的 for inforto

ac5474012 发表于 2009-10-2 16:55:02

#include <IE.au3>
_IELinkGetCollection ( 对象变量 [, 索引 = -1] )
我觉得_IECreate("http://www.uname.cn/dic/zidian.asp",79)这样应该就能得到我想要的第79个,但是却不行。它说它返回的是一个对象集合。所以我就要一个一个看吗?
能不能一下子就提取出我想要的第79个?

sxd 发表于 2009-10-2 16:56:34

我的意思是 就是历遍加判断就行了
If $i = 75 Then
MsgBox(0, "", $oLink.href)
ExitLoop
EndIf

afan 发表于 2009-10-2 17:09:07

For $oLink In $oLinks
    If StringRegExp($oLink.href, 'http://www.uname.cn/html/dic/.+') then $s = $oLink.href
Next
MsgBox(0, "Link Info", $s)是不是这意思?

ac5474012 发表于 2009-10-2 18:17:29

算是吧,我就是想更优化点。

afan 发表于 2009-10-2 18:41:33

#include <IE.au3>
$oIE = _IECreate("http://www.uname.cn/dic/zidian.asp")
$a = _IEGetObjByName($oIE, "gb")
_IEFormElementSetValue($a, "国")
$b = _IEGetObjByName($oIE, "Submit")
_IEAction($b, "click")
_IELoadWait($oIE)
$sHTML = _IEBodyReadHTML($oIE)
$Link = StringRegExp($sHTML, 'href="(/html/dic/[^"]+)">', 3)
If @Error = 0 Then$oLink = 'http://www.uname.cn' & $Link
MsgBox(0, "Link Info", $oLink)
页: [1]
查看完整版本: 如何获取一个网页中的文本超链接的链接