没有得到我期望从DOM解析中得到的结果

时间:2019-06-25 21:45:44

标签: php parsing dom

将代码合并在一起阅读5个不同的站点。当然,我在日期的输出中特别缺少一些东西,然后我没有得到实际的文章内容,甚至因为表格中的联系信息而没有必要对其进行分类。也想下载图像,以便将其作为附件发送。最终的目的是构建和发送电子邮件,以便我的手机可以生成联系卡。尝试轻松地将Web数据与移动设备合并。

在具有跨度itemprop的日期,我没有解析该信息的任何信息。 在这篇文章中,我假设它会发回一个数组,该数组必须与一些新的html放在一起,以使其看起来干净。 我注意到,当我回显整个html时,图像会从我的网站上显示出来,但无法将它们作为附件发送,因此我不得不提取这些数据并将其保存在我假设的单独代码中,但是我发现了如何获取所有图像因为大多数示例都是在某处刮取IMBD或一些图片库。我只想要文章中的图片。

        <?php

        ini_set('display_errors', 1);
        ini_set('display_startup_errors', 1);
        error_reporting(E_ALL);

        include_once('simple_html_dom.php');

        // Scrape a web page from the web
        $URI = curl_get('http://www.prweb.com/releases/chicago_based_startup_mcpond_aims_to_be_the_uber_of_manufacturing_industry/prweb16233855.htm');

        $html = new simple_html_dom();
        $html = str_get_html($URI); // here we use SimpleHTML DOM library to create a DOM-structure

        // here we use SimpleHTML DOM library to create a DOM-structure
        $dom = str_get_html($html); 
        $html->load($dom);


        // parse the result into strings

        $doc = $html;
        // Display the page Make sure i got it for testing.
        //echo $doc;

        $date_published =  $html->find('.datePublished'); // <span itemprop="datePublished">June 25, 2019</span>   
        echo $date_published[0];
        $article_full= $html->find('p[class=responsiveNews]');
        print_r ($article_full);
        //$result = $html->find('b, p');
        //$contact_table = stuff i haven't figured out yet;
        //$download_image(s) = Download images so i can send as an attachment via email;

        //Send to my phone via text/email with the pictures as attachments.

        function curl_get($url, $referer = "https://www.google.com/") {
         $ch = curl_init();  // Initialising cURL
         curl_setopt($ch, CURLOPT_URL, $url);  // Setting cURL's URL option with the $url variable passed into the function
         curl_setopt($ch, CURLOPT_REFERER, $referer); // from where we come to the site
         curl_setopt($ch, CURLOPT_HEADER, 0);  // No headers
         curl_setopt($ch, CURLOPT_COOKIE, "login=User;password=123test");  // This is how we set cookie.
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  // Setting cURL's option to return the webpage data
         $data = curl_exec($ch);  // Executing the cURL request and assigning the returned data to the $data variable
         curl_close($ch);    // don’t forget about closing cURL
         return $data;   // Returning the data from the function
        }

        function fred($val="NOTHING DECLARED???")
        {
          $type = gettype($val);
          echo '<h3 style="background-color:red; color:#000; ">';
            echo '$type ==> ' .$type;
          echo '</h3>';

          echo '<pre>';
            print_r($val);
          echo '</pre>';
        }
        ?>

尝试通过单独的变量获取日期,文章,图片和联系信息,以便将其重新放回我发送到手机的vCard +模板中

0 个答案:

没有答案