找回密码
 加入
搜索
查看: 9343|回复: 22

[系统综合] 帮我写一个正规表达式,谢.

 火.. [复制链接]
发表于 2012-9-21 21:16:43 | 显示全部楼层 |阅读模式
读出一个网页的全部内容后,得到PDF ( xxxK),这个XXX是变化的. 想通过正则得到这个PDF的链接,就是PDF (125 K)的前面.以面是部分内容.
<LI><!-- return to gateway -->
<LI>
<DIV class=icon_exportarticlesci_dir title="Export citation">
<DIV class=icon></DIV><A href="/science?_ob=DownloadURL&amp;_method=confirm&amp;_eidkey=3-s2.0-B9780122841514500002&amp;count=1&amp;_docType=FLA&amp;zone=toolbar&amp;_acct=C000228598&amp;_version=1&amp;_userid=10&amp;md5=058f256059053d8e6012440cf676943f">Export citation</A> </DIV>
<LI>
<DIV class=icon_pdf>
<DIV class=icon></DIV><A class="big pdf ext_sdlink" id=pdfLink title="Download PDF" style="CURSOR: pointer" href="http://pdn.sciencedirect.com/science?_ob=MiamiImageURL&amp;_cid=275975&amp;_user=10&amp;_pii=B9780122841514500002&amp;_check=y&amp;_origin=article&amp;_zone=toolbar&amp;_coverDate=31-Dec-2005&amp;_idxType=GenInfo&amp;view=c&amp;originContentFamily=nonserial&amp;wchp=dGLbVlB-zSkWb&amp;md5=e2daf201315801e5860469956abdcac3&amp;pid=3-s2.0-B9780122841514500002-main.pdf" target=newPdfWin suggestedArtURL="http://www.sciencedirect.com/science/suggestedArt/citeList/pii/B9780122841514500002/eid/3-s2.0-B9780122841514500002/nonserial" pdfurl="http://pdn.sciencedirect.com/science?_ob=MiamiImageURL&amp;_cid=275975&amp;_user=10&amp;_pii=B9780122841514500002&amp;_check=y&amp;_origin=article&amp;_zone=toolbar&amp;_coverDate=31-Dec-2005&amp;_idxType=GenInfo&amp;view=c&amp;originContentFamily=nonserial&amp;wchp=dGLbVlB-zSkWb&amp;md5=e2daf201315801e5860469956abdcac3&amp;pid=3-s2.0-B9780122841514500002-main.pdf" jQuery17104474407950526011="2">PDF (125 K)</A> </DIV>
<LI class=optionsPos>
<DIV id=moreOptionsButton title="Show article options"><A href="#">More options...</A>
<DIV class=down_sci_dir></DIV></DIV><!-- More Options Starts-->
<DIV class="articleOptions articleOptionssci_dir" id=moreOptionsMenu>
<UL>
<LI>
 楼主| 发表于 2012-9-21 21:22:01 | 显示全部楼层
晕,好像真实地址不在这附近.那就帮我写一个正则,能读出这个PDF (125k)吧,这个125是变化的.
发表于 2012-9-21 22:05:00 | 显示全部楼层
PDF\s*\(\d*k\)
 楼主| 发表于 2012-9-21 22:21:48 | 显示全部楼层
26011="2">PDF (125 K)</A> </DIV>
PDF和(有空格
125和K有空格
你写的好像不对吧.
发表于 2012-9-22 09:49:14 | 显示全部楼层
PDF\s*\(\d*\s*k\)
 楼主| 发表于 2012-9-22 10:30:04 | 显示全部楼层
#include <IE.au3>
; #include <IEQuery.au3>
$oIE = _IECreate("http://www.sciencedirect.com/science/article/pii/B9780122841514500002")
;_IEQuery通用获取元素对象
; $Ele = _IEQuery($oIE,"A",'class="big pdf ext_sdlink",outertext="PDF (125 K)"')

$PDF= StringRegExp($oIE,'PDF\s*\(\d*\s*k\)', 1)
MsgBox(0,'999',$PDF)
_IELinkClickByText($oIE,$PDF)


还是不对,总是点击不了.
发表于 2012-9-22 11:34:25 | 显示全部楼层
$oIE不是字符串对象。
 楼主| 发表于 2012-9-22 11:43:30 | 显示全部楼层
$oIE不是字符串对象。
seeyou 发表于 2012-9-22 11:34



    那怎么办?要把$oIE变成字符串吗?可以我是按照别人写的代码我改了改,而且别人写的我没改的话,是可以运行的,不知道我一改不就行了.具体代码应该是什么样的呢.
发表于 2012-9-22 12:05:50 | 显示全部楼层
Try this: $code = _IEDocReadHTML($oIE)
 楼主| 发表于 2012-9-22 12:32:54 | 显示全部楼层
Try this: $code = _IEDocReadHTML($oIE)
seeyou 发表于 2012-9-22 12:05



    #include <IE.au3>
; #include <IEQuery.au3>
$oIE = _IECreate("http://www.sciencedirect.com/science/article/pii/B9780122841514500002")
;_IEQuery通用获取元素对象
; $Ele = _IEQuery($oIE,"A",'class="big pdf ext_sdlink",outertext="PDF (125 K)"')

$PDF= StringRegExp($oIE,'PDF\s*\(\d*\s*k\)', 1)
MsgBox(0,'999',$PDF)
$code = _IEDocReadHTML($oIE)
_IELinkClickByText($code,$PDF)


还是不好用,没反应,我感觉你说的不对.
发表于 2012-9-22 13:32:25 | 显示全部楼层
本帖最后由 seeyou 于 2012-9-22 13:35 编辑

我说的的确不能帮你打成最后的结果。但是可以帮助你看到代码里的错误。
下面一段代码可以帮助你实现你要的结果,不过你要注意浏览器的行为(有没有把弹出的网页拦截了),当然最终能否实现还需要你自己进行微调。
#include <IE.au3>

Local $oIE = _IECreate("http://www.sciencedirect.com/science/article/pii/B9780122841514500002")
Local $oLinks = _IELinkGetCollection($oIE)

$sSearchString = "PDF (125 K)"
For $oLink in $oLinks
   Local $sLinkText = _IEPropertyGet($oLink, "innerText")
    If StringInStr($sLinkText, $sSearchString) Then
       _IEAction($oLink, "click")
   endif
Next
发表于 2012-9-22 15:47:40 | 显示全部楼层
PDF[\s]*\((.*?)K
 楼主| 发表于 2012-9-22 18:25:53 | 显示全部楼层
我说的的确不能帮你打成最后的结果。但是可以帮助你看到代码里的错误。
下面一段代码可以帮助你实现你要的 ...
seeyou 发表于 2012-9-22 13:32



    你写的这个有正则表达式在里面吗?我的要求你没看清吧,那个PDF后面的数字(125k)是会变化的.
 楼主| 发表于 2012-9-22 19:01:20 | 显示全部楼层
PDF[\s]*\((.*?)K
jtzxgfy 发表于 2012-9-22 15:47



    你写的也不对吧,K后面还有括号的.你的有吗?
发表于 2012-9-22 19:48:32 | 显示全部楼层
PDF[\s]*\((.*?)K
结果:125
要提取括号内的:PDF[\s]*\((.*?K)\)
结果:125 K
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-7 21:38 , Processed in 0.084636 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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