Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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 如何更改从其他网站提取的数据的类别_Php_Html_Css_Web Scraping - Fatal编程技术网

Php 如何更改从其他网站提取的数据的类别

Php 如何更改从其他网站提取的数据的类别,php,html,css,web-scraping,Php,Html,Css,Web Scraping,我用这个URL从一个网站上搜集了一些数据 <?php $opts = array( 'http'=>array( 'method'=>"GET", 'header'=>"Accept-language: en\r\n" . "Cookie: foo=bar\r\n" ) ); $context = stream_context_create($opts); $file = file_

我用这个URL从一个网站上搜集了一些数据

<?php   
    $opts = array(
    'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
          "Cookie: foo=bar\r\n"
    )
    );
    $context = stream_context_create($opts);
    $file = file_get_contents('http://www.somewebsite.com/', false, $context);
    $arr = explode('<div class="someclass"', $file);
    $a = strpos($arr[1],'<h1>');
    $b = substr($arr[1],$a);
    $arr2 =  explode('</h1>', $b);
    echo $arr2[0];
?>  

您可以发布在
$arr2[0]
中显示的HTML吗?看起来您已经隔离了一个
元素。最简单的方法可能是:(a)剥离页面中的样式定义,以及(b)从页面中为类创建自己的样式定义。例如..someclass{your style defs}。我试图与我的类一起使用,但它不起作用,只有当我与来自另一个网站的样式一起使用它时,它才起作用。使用查看源代码,查看问题所在,尝试html验证。很明显,您的html结构有缺陷。Inspector试图修复它,它不是您输出的精确表示。试试看,你会发现哪里出了问题。CSS不是火箭科学,如果格式正确,它只会工作。