cURL未加载样式/CSS [英] cURL not loading style/css

查看:51
本文介绍了cURL未加载样式/CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个非常简单的cURL代码,应该检索页面的数据...好吧,它实际上确实显示了页面的内容... 有时,而且在大多数其他情况下,样式都一团糟,因为字体没有加载,大多数图像和图形元素也没有加载.如果我更改了要显示的页面的URL,结果会有所不同,有些页面加载没有问题,而其他页面根本没有显示任何内容.

So I have this pretty simple cURL code that should be retrieving the data of a page... Well, it actually does show the page's contents... sometimes, and also, most of the other times the style is all messed up, as the fonts aren't loading and neither do most of the images and graphic elements. The results vary if I change the URLs of the page I want to show, with some loading no problem, others not showing anything at all.

我想cURL如何处理css有问题,如何正确加载css?

I guess there's a problem with how the cURL handles the css, how can I have it load it correctly?

<?php
    $ch = curl_init();

    $url = 'http://3amigos.com.mx/';

    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (http://www.googlebot.com/bot.html)');
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);

    $data = curl_exec($ch);

    echo $data;
?>
ABCDEF

目前,有时它甚至不加载任何格式的ABCDEF,而有时则页面完全是空的.

As it is right now, sometimes it doesn't even load anything but the ABCDEF without any format, and some other times the page is completely empty.

推荐答案

当您发送带有curl的http请求时,curl接收响应并将其提供给您.如果响应中嵌入了样式,则可以使用您的浏览器未启用/有CURL 来显示此样式.但是,如果样式/资源在属性 src href 上具有完整的URI,则可以看到在您的浏览器上应用此/WITH CURL .

When you send http request with curl, curl take the response and give it to you. If the response have a styles embedded, you can show this apply with YOU BROWSER NOT ON/WITH CURL. BUT if the styles/resources have full URI on the attribute src, href, you can see apply this ON YOU BROWSER NOT ON/WITH CURL.

Curl不是HTML,JS,CSS解释器.

Curl只是使用各种协议(例如HTTP,HTTPS等)传输数据的命令行.

Curl is only command line for transferring data using various protocols like HTTP, HTTPS, ...

您可能需要了解 PhantomJS 另一种解决方案(太慢了)是获取响应并解析它以找到所有要打开并获取内容并将其嵌入的< link> (css样式链接)...(我认为这是个坏主意,但可以)

Another solution(too slow) is get response and parse it to find all <link>(css style link) to open and get content and embed it...(I think this is bad idea, but work)

这篇关于cURL未加载样式/CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆