1

您好,我有一个脚本,但是当我尝试捕获我需要的信息时,我不能这是我想要获得的 html 代码的一部分:

<div class="pretty-container " >
2100.0
  </div>

所以在我的套接字 y 上尝试这样做以获得 2100.0(2100.0 它是一个可变数字):

on *:sockread:foo: {
 var %read
 sockread %read
 if ($regex(%read,<div class="pretty-container " >(.*)<\/div>)) {
    echo -s price founded: $regml(1)
    ; - here i try to catch the 2100.0 number
    sockclose $sockname
 }
}

但这不起作用我相信这是因为数字和在另一行。请有人帮我解决这个问题?

提前感谢,

卡洛斯

4

1 回答 1

1

您使用的sockread命令一次只读取一行。由于您要查找的数据分布在多行中,因此您的正则表达式将永远找不到匹配项。

对此的解决方案是简单地检查当前行是否包含<div class="pretty-container " >,如果是,则将下一行的数据存储在另一个变量中:

  var %read, %number
  sockread %read
  if (<div class="pretty-container " > isin %read) {
    sockread %number
    echo -s Number: %number
    sockclose $sockname
  }
于 2013-11-24T12:45:21.300 回答