找回密码
 加入
搜索
查看: 1824|回复: 10

求一个包含中文的正则表达式。

[复制链接]
发表于 2009-7-13 15:32:44 | 显示全部楼层 |阅读模式
本帖最后由 minterz 于 2009-7-15 11:04 编辑

要搜索网页源码中的部分字符,有中文的,小弟才疏学浅,实在搞不定了,求教各位。。

就是在网页源码中,固定的两个字符串之间的字符串。

如:
-------------------------------------------------------------------------------------
</form>
<table width="80%"  border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
                <td align="center"><h3>ip138.com IP查询(搜索IP地址的地理位置)</h3></td>
        </tr>
        <tr>
                <td align="center">您的IP地址是:[221.213.34.109] 来自:云南省昆明市 网通<br/><br/></td>
        </tr>
        <tr>
                <td align="center"></td>
        </tr>
        <tr>
                <td align="center">如果您发现查询结果不详细或不正确,请使用<a href="ip_add.asp?ip=221.213.34.109"><font color="#006600"><b>IP数据库自助添加</b></font></a>功能进行修正<br/><br/>
                <iframe src="/jss/bd_468x15.htm" frameborder="no" width="468" height="15" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe><br/><br/></td>
        </tr>
        <form method=post action="ips8.asp" name="ipform" onsubmit="return checkIP();">
        <tr>
                <td align="center">IP地址或者域名:<input type="text" name="ip" size="16"> <input type="submit" value="查询"><input type="hidden" name="action" value="2"></td>
        </tr><br>
<br>
        </form>

----------------------------------------------------------------------------------
在这样,有空白符,有换行符,有中文的源码中,找到两个固定字符串
“来自:” 这个字符串  和  “<br/><br/></td>”这个字符串中间“云南省昆明市 网通”这个字符串。

谢谢了。。
发表于 2009-7-13 15:56:22 | 显示全部楼层
$a = stringregexp($file, '(?U)本站主数据:(.+)</li>', 1, 1)
 楼主| 发表于 2009-7-13 16:09:02 | 显示全部楼层
本帖最后由 minterz 于 2009-7-13 16:17 编辑

哎呀,不行啊,msgbox出来的是0啊,,不过还是感谢热心回答。。。
网页就是这个了,,http://www.ip138.com/ips8.asp
只要能用正则 搜索到 ip的 具体地理位置就可以了。。
发表于 2009-7-13 17:58:33 | 显示全部楼层
本帖最后由 即即 于 2009-7-14 10:23 编辑

3# minterz

StringRegExp($file, “(?<=] 来自:)[^\x00-\xff]+(?=\s)”, 1)
 楼主| 发表于 2009-7-14 00:10:27 | 显示全部楼层
楼上的,谢谢了,不过这个完全不能用

(?<=] 来自:)[^\x00-\xff]+(?=\s)
表达式错误。。au3是这样提示的。。
发表于 2009-7-14 01:40:38 | 显示全部楼层
StringRegExp($file, '(?<=] 来自:)[^\x00-\xff]+(?=\s)', 1)
漏了两个'
发表于 2009-7-14 10:27:06 | 显示全部楼层
6# lynfr8

对,漏了引号,谢谢提醒。
 楼主| 发表于 2009-7-14 21:11:51 | 显示全部楼层
$file= InetGet ("http://www.ip138.com/ips8.asp","c:/test.txt")

$array =  StringRegExp($file, '(?<=] 来自:)[^\x00-\xff]+(?=\s)', 1)


for $i = 0 to UBound($array) - 1
    msgbox(0, "ip是 ", $array[$i])
Next

---------------------------
不知道上面对不对,不过还是不能返回需要的ip地理位置啊。。。
哪里有问题,请指教。。。
发表于 2009-7-14 21:55:28 | 显示全部楼层
InetGet ("http://www.ip138.com/ips8.asp","c:/test.txt")
$file = FileRead("c:/test.txt")
$array =  StringRegExp($file, '(?<=] 来自:)[^\x00-\xff]+(?=\s)', 1)
for $i = 0 to UBound($array) - 1
    msgbox(0, "ip是 ", $array[$i])
Next
发表于 2009-7-14 22:00:06 | 显示全部楼层
$file=_IEDocReadHTML("http://www.ip138.com/ips8.asp")
--------------------------------------------------------------------------------
返回整个文档的HTML源代码
 楼主| 发表于 2009-7-15 11:04:46 | 显示全部楼层
各位高手,真是太感谢了,终于成功了。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-3 03:50 , Processed in 0.074834 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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