找回密码
 加入
搜索
查看: 3984|回复: 11

[IE类操作] 有没有什么办法不用IECreate,有没有什么办法用后台读取网页呢?

  [复制链接]
发表于 2012-12-27 10:59:42 | 显示全部楼层 |阅读模式
#include <ie.au3>

    $oie=_IECreate("http://www.sciencedirect.com/science/article/pii/B9780122841514500002",1,1,1,0)
    _IELoadWait($oie)
    $links=_IELinkGetCollection($oie)
    For $link In $links
            If StringLower($link.title)="download pdf" Then
                    MsgBox(0,"",$link.href)
                    ExitLoop
            EndIf
    Next
发表于 2012-12-27 15:15:35 | 显示全部楼层
#Include <WinHTTP.au3>
_WinHttpReadData
发表于 2012-12-27 15:39:40 | 显示全部楼层
本帖最后由 netegg 于 2012-12-27 15:42 编辑

[au3]#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinHttp.au3>

Opt('MustDeclareVars', 1)

Global $iMemo,$hOpen,$hConnect,$hRequest,$sChunk
_mani()

Func _mani()
    GUICreate("HTTP Data", 800, 600)
    $iMemo = GUICtrlCreateEdit("", 2, 2, 796, 596, $WS_VSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()

    ; 初始化并获取会话句柄
    $hOpen = _WinHttpOpen()
    $hConnect = _WinHttpConnect($hOpen, "sciencedirect.com")
    $hRequest = _WinHttpOpenRequest($hConnect, "POST", "/science/article/pii/B9780122841514500002")
    _WinHttpSendRequest($hRequest)
    _WinHttpReceiveResponse($hRequest)
   
    If _WinHttpQueryDataAvailable($hRequest) Then
      While 1
        $sChunk = _WinHttpReadData($hRequest) ; 读取数据
        If @error Then ExitLoop
        MemoWrite($sChunk)
      Wend
    else
      MsgBox(48, "Error occurred", "Site is experiencing problems.")
    EndIf

; 关闭句柄
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>__WINHTTP_STATUS_CALLBACK
; 向memo控件写入信息
Func MemoWrite($sMessage = "")
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite[/au3]
发表于 2012-12-27 15:48:13 | 显示全部楼层
本帖最后由 netegg 于 2012-12-27 15:51 编辑

返回的数据中可以找到
    <a id="pdfLink"  href="http://pdn.sciencedirect.com/science?_ob=MiamiImageURL&_cid=275975&_user=10&_pii=B9780122841514500002&_check=y&_origin=article&_zone=toolbar&_coverDate=2005--31&_idxType=GenInfo&view=c&originContentFamily=nonserial&wchp=dGLbVBA-zSkWA&md5=ca807b83cfe0d045da65892f34e8a96c&pid=3-s2.0-B9780122841514500002-main.pdf" target="newPdfWin"  pdfurl="http://pdn.sciencedirect.com/science?_ob=MiamiImageURL&_cid=275975&_user=10&_pii=B9780122841514500002&_check=y&_origin=article&_zone=toolbar&_coverDate=2005--31&_idxType=GenInfo&view=c&originContentFamily=nonserial&wchp=dGLbVBA-zSkWA&md5=ca807b83cfe0d045da65892f34e8a96c&pid=3-s2.0-B9780122841514500002-main.pdf" suggestedArtURL="http://www.sciencedirect.com/science/suggestedArt/citeList/pii/B9780122841514500002/eid/3-s2.0-B9780122841514500002/nonserial" class="big pdf ext_sdlink" style="cursor:pointer" title="Download PDF" >PDF  (125 K)</a>
下载的操作lz自己想想吧
 楼主| 发表于 2012-12-27 18:18:07 | 显示全部楼层
怎么下载呢?我得到这么多的代码怎么下载呢?怎么提取出要下载的地址呢?如果不用正则的话,又应该怎么操作呢?
 楼主| 发表于 2012-12-27 18:26:06 | 显示全部楼层
给我的代码出错,说我没有 winhttpConstants.au3文件,而我有的是winhttp.au3,我把winhttp.au3改为 winhttpConstants.au3后,软件又提示缺少winhttp.au3
发表于 2012-12-27 18:52:00 | 显示全部楼层
本帖最后由 netegg 于 2012-12-27 18:54 编辑

回复 6# sex123
把winhttpconstants的内容复制到winhttp文件开始

pdfurl就是pdf源文件的指向地址

至于怎么下载,自己去想办法,帮助文件里有下载文件的函数
 楼主| 发表于 2012-12-27 20:05:00 | 显示全部楼层
这个只是一个例子,这样的网站别的文件下载需要登陆和代理,问一下,这个能实现吗?
 楼主| 发表于 2012-12-27 20:07:55 | 显示全部楼层
还是出错,能不能把你UDF传给我一份?
发表于 2012-12-27 22:34:29 | 显示全部楼层
本帖最后由 netegg 于 2012-12-27 22:37 编辑

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinHTTPConstants.au3>
#include <WinHttp.au3>
改成这样呢
代理那些乱七八糟的东西,request里可以加参数
另外代理不代理似乎和pdf的地址无关吧,代码只是获取pdf链接地址用的
 楼主| 发表于 2012-12-28 09:01:01 | 显示全部楼层
WinHTTPConstants.au3
哪里有下载的呢?
发表于 2012-12-28 10:56:31 | 显示全部楼层
有winhttp的话,不可能没有constants,除非用的是exe帮助里的,那个里面我把两个文件合并到一个文件里了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-15 23:22 , Processed in 0.080581 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表