我正在用php编写一个网站爬虫,我已经有代码可以从网站中提取所有链接。问题是:网站使用绝对和相对url的组合。
示例(http被替换为hxxp,因为我不能发布超链接):
hxxp://site.com/
site.com
site.com/index.php hxxp://site.com/hello/index.php /hello/index.php hxxp://site2.com/index.php site2.com/index.php 我无法控制链接(它们是绝对/相对的),但我确实需要跟随它们。我需要将所有这些链接转换为绝对URL。我该如何在php中做到这一点?
示例(http被替换为hxxp,因为我不能发布超链接):
hxxp://site.com/
site.com
site.com/index.php hxxp://site.com/hello/index.php /hello/index.php hxxp://site2.com/index.php site2.com/index.php 我无法控制链接(它们是绝对/相对的),但我确实需要跟随它们。我需要将所有这些链接转换为绝对URL。我该如何在php中做到这一点?