似乎无法正确抓取美军网站以获取数据


Cant seem to properly scrape the US army website for data

我试图为军队刮一页MOS,但似乎我做错了。

<?php
    $army = "http://www.goarmy.com/careers-and-jobs/browse-career-and-job-categories/administrative-support.AR-both.html";
$fp = file_get_contents($army);
$dom = new DOMDocument();
@$dom->loadHTML($fp);
$classes = $dom->getElementsByTagName("div");
foreach($classes as $class){        
    if($class->getAttribute("class") == "job-desc")continue;
    foreach($class->getElementsByTagName("a") as $c){
        echo $c;
    }
    break;
}
?>

是我一直在尝试的,但我似乎无法正确处理。 我希望有一个像jQuery这样的选择器工具,或者XPATH来处理我正在寻找的东西。

我试图找到:

$("div.job-desc > h4 > a").text();
$("div.job-desc > ul > li").text();

我正在为每个分支编写国家MOS词典,然后在不久的将来扩展到其他国家。

我在想我可以将类似jquery的选择器修改为xpath,但似乎XPath可能仅适用于XML,而不是HTML文档。

如果你使用这个:

http://davidwalsh.name/php-notifications

并做这样的事情:

下载并包括:simple_html_dom.php做:

$html = file_get_html($army);
foreach($html->find('div.job-desc > h4 > a') as $row){
   echo $row->innertext."'n";
}

它会做你想做的事。

为了装腔作势,它把每个人都放在一条新线上...... 如果需要,请根据需要解析$row>内部文本