谷歌网址上的后期处理 [英] post processing on google urls
本文介绍了谷歌网址上的后期处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用正则表达式从 Google 搜索结果中抓取了一些网址.它为我提供了以下格式的链接.现在,我只想要方案和主机.任何正则表达式的想法?我尝试了 url_parse,但由于前缀/url?q=",它似乎不起作用.
I have grabbed some urls from Google search results using a regular expression. It has provided me the links in the format given below. Now, I just want the scheme and the host. Any regex ideas? I tried url_parse, but it does not seem to work because of the prefix '/url?q='.
/url?q=http://www.fertile-focus.com/&sa=U&ei=dTTTU7L2A4egugSY44LgAQ&ved=0CCsQFjAEOGQ&usg=AFQjCNEwG9ntbG0ZtqbqjJNSfVTlqQJYmg
/url?q=http://www.genetests.org/&sa=U&ei=dTTTU7L2A4egugSY44LgAQ&ved=0CDgQFjAGOGQ&usg=AFQjCNFiux9o5YIUGP4P8B_oG_J6iD1Y6g
现在只需要
http://www.fertile-focus.com
http://www.genetests.org
推荐答案
Regex 匹配上面提到的以 /url?q=
开头的 URL,
Regex to match the above mentioned URL's which are preceded by /url?q=
,
\/url\?q=\K.*?(?=\/&)
或
www\.[^.]*\.(?:org|com)
您的 PHP 代码将是,
Your PHP code would be,
<?php
$url = <<< 'EOT'
/url?q=http://www.fertile-focus.com/&sa=U&ei=dTTTU7L2A4egugSY44LgAQ&ved=0CCsQFjAEOGQ&usg=AFQjCNEwG9ntbG0ZtqbqjJNSfVTlqQJYmg
/url?q=http://www.genetests.org/&sa=U&ei=dTTTU7L2A4egugSY44LgAQ&ved=0CDgQFjAGOGQ&usg=AFQjCNFiux9o5YIUGP4P8B_oG_J6iD1Y6g
EOT;
$regex = '~\/url\?q=\K.*?(?=\/&)~';
preg_match_all($regex, $url, $matches);
var_dump($matches);
?>
输出:
array(1) {
[0]=>
array(2) {
[0]=>
string(28) "http://www.fertile-focus.com"
[1]=>
string(24) "http://www.genetests.org"
}
}
这篇关于谷歌网址上的后期处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文