找回密码
 加入
搜索
查看: 5986|回复: 8

[系统综合] 如何进行变量操作,提取变量中的特定字符?

  [复制链接]
发表于 2012-9-18 02:30:46 | 显示全部楼层 |阅读模式
本帖最后由 sex123 于 2012-9-18 02:32 编辑

现有一个变量link,link内容如下:
</b></span><span style="float:left;width:90%"><a  href="http://dx.doi.org/10.1097/gme.0b013e31826015ca" target="_blank">Lippincott Williams & Wilkins</a></span></p><div class="clear"></div><p><font color="gray">
</b></span><span style="float:left;width:90%"><a  href="http://www.medultrason.ro/feednlm/linkout/2012/14/141" target="_blank">Iuliu Hatieganu Medical Publishing House</a><br><a  href="http://gateway.proquest.com/openurl?url_ver=Z39.88-2004&res_dat=xri:pqm&rft_val_fmt=info:ofi/fmt:kev:mtx:journal&genre=article&issn=1844-4172&volume=14&issue=2&spage=141" target="_blank">ProQuest Information and Learning</a><br><a  href="http://openurl.ebscohost.com/linksvc/linking.aspx?genre=article&sid=PubMed&issn=1844-4172&title=Med%20Ultrason&volume=14&issue=2&spage=141&atitle=Ultrasound%20assessment%20of%20the%20elbow.&aulast=Radunovic&date=2012" target="_blank">EBSCO</a></span></p><div class="clear"></div><p><font color="gray">
</b></span><span style="float:left;width:90%"><a  href="http://dx.doi.org/10.1002/ijc.27789" target="_blank">John Wiley & Sons, Inc.</a></span></p><div class="clear"></div><p><font color="gray">
</b></span><span style="float:left;width:90%"><a  href="http://www.jbc.org/cgi/pmidlookup?view=long&pmid=22829587" target="_blank">HighWire Press</a></span></p><div class="clear"></div><p><font color="gray">
</b></span><span style="float:left;width:90%"><a  href="http://dx.doi.org/10.1002/path.4055" target="_blank">John Wiley & Sons, Inc.</a><br><a  href="http://ovidsp.ovid.com/ovidweb.cgi?T=JS&PAGE=linkout&SEARCH=22653794.ui" target="_blank">Ovid Technologies, Inc.</a><br><a  href="http://olinks.ohiolink.edu/ejc-redir.php?issn=00223417&volume=228&issue=1&spage=88&date=2012&aulast=Hur" target="_blank">OhioLINK Electronic Journal Center</a><br><a  href="http://openurl.ebscohost.com/linksvc/linking.aspx?genre=article&sid=PubMed&issn=0022-3417&title=J%20Pathol&volume=228&issue=1&spage=88&atitle=Up-regulated%20expression%20of%20sulfatases%20(SULF1%20and%20SULF2)%20as%20prognostic%20and%20metastasis%20predictive%20markers%20in%20human%20gastric%20cancer.&aulast=Hur&date=2012" target="_blank">EBSCO</a></span></p><div class="clear"></div><p><font color="gray">

现在要求提取link中的http链接,并且把http链接分类到不同的其他变量中,比如有http://openurl.ebscohost.com/...字样的http地址分给EBSCO变量
http://dx.doi.org的链接分给doi变量
http://www.jbc.org/cgi/pmidlookup?view=long&pmid=22829587则分给jbc变量
如何操作呢?我是指把全部的链接的完整地址分配给不同的变量.
发表于 2012-9-18 09:48:48 | 显示全部楼层
[0]|http://dx.doi.org/10.1097/gme.0b013e31826015ca
[1]|http://www.medultrason.ro/feednlm/linkout/2012/14/141
[2]|http://gateway.proquest.com/openurl?url_ver=Z39.88-2004&res_dat=xri:pqm&rft_val_fmt=info:ofi/fmt:kev:mtx:journal&genre=article&issn=1844-4172&volume=14&issue=2&spage=141
[3]|http://openurl.ebscohost.com/linksvc/linking.aspx?genre=article&sid=PubMed&issn=1844-4172&title=Med%20Ultrason&volume=14&issue=2&spage=141&atitle=Ultrasound%20assessment%20of%20the%20elbow.&aulast=Radunovic&date=2012
[4]|http://dx.doi.org/10.1002/ijc.27789
[5]|http://www.jbc.org/cgi/pmidlookup?view=long&pmid=22829587
[6]|http://dx.doi.org/10.1002/path.4055
[7]|http://ovidsp.ovid.com/ovidweb.cgi?T=JS&PAGE=linkout&SEARCH=22653794.ui
[8]|http://olinks.ohiolink.edu/ejc-redir.php?issn=00223417&volume=228&issue=1&spage=88&date=2012&aulast=Hur
[9]|http://openurl.ebscohost.com/linksvc/linking.aspx?genre=article&sid=PubMed&issn=0022-3417&title=J%20Pathol&volume=228&issue=1&spage=88&atitle=Up-regulated%20expression%20of%20sulfatases%20(SULF1%20and%20SULF2)%20as%20prognostic%20and%20metastasis%20predictive%20markers%20in%20human%20gastric%20cancer.&aulast=Hur&date=2012
共有10个链接地址,有3个是一类,还有7个各自成类,楼主你要这样分类感觉意义不大。要不在直接提取到数组里后,再赋值给你所确定的变量名?
 楼主| 发表于 2012-9-18 11:51:15 | 显示全部楼层
共有10个链接地址,有3个是一类,还有7个各自成类,楼主你要这样分类感觉意义不大。要不在直接提取到数组里 ...
shqf 发表于 2012-9-18 09:48



    你的想法很好,我想要的不是结果,而是怎么提取的过程,有代码吗?我是初学者,我已经上网找了一圈了,只知道用string命令吧,但是没有会用.
发表于 2012-9-18 17:21:06 | 显示全部楼层
回复 3# sex123
#include<array.au3>
$file="D:\UserFile\Desktop\2222.txt"
$txt=FileRead($file)
$array=StringRegExp($txt,'http[^"]+',3)
_ArrayDisplay($array)
这个是取链接的方法。至于赋值也很简单。只是里面符合同一条件的链接那么多,给一个变量赋值也只能保存最后一次的赋值啊,到底里面哪个是你要的
发表于 2012-9-18 17:24:43 | 显示全部楼层
回复 3# sex123
这是正则,http://www.autoitx.com/forum.php ... t=%D5%FD%D4%F2%2B30可以学习正则。
发表于 2012-9-19 08:17:57 | 显示全部楼层
给出我提取链接的正则代码,供楼主学习正则时多个参考吧
$array=StringRegExp($txt,'"(http://.+?)"',3)
发表于 2012-9-19 16:37:18 | 显示全部楼层
#include<array.au3>
$file="2222.txt"
$txt=FileRead($file)
$array=StringRegExp($txt,'http[^"]+',3)
_ArrayDisplay($array)
For $i= 0 To UBound($array)-1
$t=StringRegExp($array[$i],"/\w+\.(\w+)\.\w+/",1)
If IsArray($t) Then
If Not IsDeclared($t[0]) Then
        Assign($t[0],$array[$i])
Else
        Assign($t[0],Execute("$"&$t[0]&'&",'&$array[$i]&'"'))
EndIf
EndIf
Next
MsgBox(0,0,Eval('doi'))


请教楼主如何使用这些变量?
 楼主| 发表于 2012-9-20 09:05:08 | 显示全部楼层
#include
$file="2222.txt"
$txt=FileRead($file)
$array=StringRegExp($txt,'http[^"]+',3)
_ArrayDis ...
pcbar 发表于 2012-9-19 16:37



我想在地址栏中分别按顺序打开不同的HTTP的地址.打开顺序由我定.可以是以文件的形式定先打开哪个地址,如果这个先打开的地址有我想要的文件,则下载PDf文件,如果没有PDF文件,则试着打开下一个地址,寻找并下载PDF文件.
发表于 2012-9-25 09:21:03 | 显示全部楼层
本帖最后由 liongodmien 于 2012-9-25 09:24 编辑

需要注意的是:在浏览器里右键打开的源码,很多时候与实际操作中的不符。
#include "array.au3"
Dim $a = FileRead("1.txt"), $EBSCO, $doi, $jbc

$EBSCO = StringRegExp($a, 'http://openurl.ebscohost.com[^"\s]+', 3)
$doi = StringRegExp($a, 'http://dx.doi.org[^"\s]+', 3)
$jbc = StringRegExp($a, 'http://www.jbc.org[^"\s]+', 3)

_ArrayDisplay($EBSCO)
MsgBox(0,0, $EBSCO[1])
_ArrayDisplay($doi)
_ArrayDisplay($jbc)
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-9 20:36 , Processed in 0.087420 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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