开发者

Regex matching for certain URLS

开发者 https://www.devze.com 2023-04-02 01:38 出处:网络
I am writing a script that needs to pick out certain URLS on a page; these URLS, for example, can be http://fiel.com/989898/etc.html followed b开发者_StackOverflow中文版y \">load</a>

I am writing a script that needs to pick out certain URLS on a page; these URLS, for example, can be http://fiel.com/989898/etc.html followed b开发者_StackOverflow中文版y ">load</a>

How could I extract these using a regex ?


In javascript:

var links = document.links;
for (var i=0; i<links.length; i++) {
  if(links[i].match(/http\:\/\/fiel\.com/i)) 
  {
  }
}

in php

$html = '<html><body>....</body></html>';
$doc = new DOMDocument();
@$doc->loadHTML($html);
$links = $doc->getElementsByTagName('a');
foreach ($links as $link) {
    if ($link->nodeValue == 'load') {
          $data = $link->getAttribute('href');
          //do whatever with href
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消