【问题标题】:Using PHP Simple Dom Parser to extract content from Indeed and Put it in a Table使用 PHP Simple Dom Parser 从 Indeed 中提取内容并将其放入表中
【发布时间】:2017-02-05 05:17:26
【问题描述】:

我正在尝试使用 PHP Simple HTML Dom Parser 解析 Indeed。 我是 PHP 新手。 我需要帮助才能从 Indeed 获取内容并将其表示为表格。

所以简而言之,我需要以下方式。

表:

公司名称 |职位名称 |职位描述 |发布日期
-------------------------------------------------- ----------
IBM |开发商 |美国开发商| 2014 年 12 月 22 日

代码:

<?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;
?>

【问题讨论】:

  • 使用the API 而不是试图抓取网站。
  • 我对 API 不满意,因为它没有提供职位描述

标签: php parsing dom foreach


【解决方案1】:

这是我到达的地方。它现在创建一个表。

<?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>';
?>

【讨论】:

    猜你喜欢
    • 2018-05-11
    • 2016-04-09
    • 1970-01-01
    • 2011-01-17
    • 1970-01-01
    • 1970-01-01
    • 2018-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多