< head>中的卷曲和相对路径 [英] Curl and relative path in <head>
本文介绍了< head>中的卷曲和相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此脚本来抓取网站:
Im ising this script to scrape a website:
<?php
$url = "http://www.nu.nl";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
echo $curl_scraped_page;
?>
输出结果在顶部的javascript,css文件中广告了错误的域。因此,我尝试使用以下方法修复该问题:
The output ads the wrong domain in javascript,css files in the head section. So I tried to fix it with:
$url = preg_replace("/<head>/i", "<head><base href='$url' />", $url, 1);
不起作用,有什么主意吗?我什么也找不到。
Doesn't work, any ideas why? I can't spot anything.
推荐答案
使用正确的变量呢? $ curl_scraped_page
是您的页面, $ url
是您的页面...但是您通过了 $ url
到 preg_replace
。
What about using the right variables? $curl_scraped_page
is your page and $url
your url... But you passed $url
to preg_replace
.
$curl_scraped_page = preg_replace("/<head>/i", "<head><base href='$url' />", $curl_scraped_page, 1);
这篇关于< head>中的卷曲和相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文