使用PHP简单的Dom解析器从确实提取内容并将其放在表中

问题描述:

我想解析确实使用PHP简单的HTML Dom解析器。 我是PHP新手。 我需要帮助才能从Indeed中获取内容并将其表示为表格。使用PHP简单的Dom解析器从确实提取内容并将其放在表中

所以总之我需要以下方式。

表:

Company Name | Job Title | job Description | Date of posting 
------------------------------------------------------------ 
IBM   | Developer | developer at US | 12/22/2014  

代码:

<?php 
include("simple_html_dom.php"); 
// Create DOM from URL or file 

$str = ''; 

// Find all images 
$html = file_get_html('https://www.indeed.com/jobs?q="IBM"&l='); 
foreach($html->find('div[data-tn-component=organicJob]') as $jobtitle) 
    $str =$str . $jobtitle->innertext . '<br>'; 
echo $str; 
?> 
+1

使用[API](https://www.indeed.com/publisher)而不是试图刮擦网站。 –

+0

我不熟悉API,因为它不提供职位描述 –

这里是我已经到了。它现在创建一个表格。

<?php 
include('simple_html_dom.php'); 
// Create DOM from URL or file 


$rowData = array(); 
echo '<table style=width:100%><tr>'; 
    echo '<th>Job title</th><th>location</th><th>company</th></tr>'; 
$html = file_get_html('https://www.indeed.com/jobs?q=IBM&l='); 

foreach ($html->find('div[data-tn-component=organicJob]') as $item){ 

    echo '<tr><td>' . $item->children(0)->plaintext . "</td>"; 

    foreach ($item->find('span[itemprop=jobLocation]') as $col2){ 


     echo '<td>' . $col2 . "</td>"; 
    } 
    foreach ($item->find('span[class=company]') as $col){ 
     echo '<td>' . $col . "</td>"; 
    } 

echo '</tr>'; 
} 
echo '</table>'; 
?>