Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 正在分析爬虫程序的url_Php_C++_Url_Urlparse - Fatal编程技术网

Php 正在分析爬虫程序的url

Php 正在分析爬虫程序的url,php,c++,url,urlparse,Php,C++,Url,Urlparse,我写了一个小爬虫,提取了5到10个站点,同时得到了链接,我得到了一些像这样的URL ../tets/index.html 如果是/test/index.html,我们可以使用基本url添加http://www.example.com/test/index.html 我能为这种Url做些什么。像这样的Url。“.”表示“父目录”,而“.”仅表示“此目录”,如bash中所示。 例如,如果您正在查看以下页面:,其中有一个类似的url:“../baz/foobar.html”,它实际上会指向我想。只需

我写了一个小爬虫,提取了5到10个站点,同时得到了链接,我得到了一些像这样的URL

../tets/index.html
如果是
/test/index.html
,我们可以使用基本url添加
http://www.example.com/test/index.html

我能为这种Url做些什么。

像这样的Url。“.”表示“父目录”,而“.”仅表示“此目录”,如bash中所示。 例如,如果您正在查看以下页面:,其中有一个类似的url:“../baz/foobar.html”,它实际上会指向我想。只需测试。

使用获取基本目录,删除
使用并将其附加到那里。像这样:

<?php
$url = "../tets/index.html";
$currentURL = "http://example.com/somedir/anotherdir";
echo dirname($currentURL).substr($url, 2);
?>

这将产生:


查看此Wikipedia页面。

您正在尝试哪种语言?@greg0ire,问题也被标记为
PHP
。请看一下标签。哦,真的!这很奇怪。。。向上投票表决bjskishore123的评论