不确定如何转换代码,我已经有html dom


Unsure on how to convert the code I already have to html dom

我已经有刮代码不工作,所以我已经搜索,发现我需要使用DOM,我不确定如何实现我已经有DOM,即使阅读后。我担心打碎什么东西。任何帮助/教程都是非常感谢的。

// get input
$link = post('link1');
$category = post('category');
$time = post('time');
// markers
$findme1 = 'https://www.mturk.com/mturk/preview?groupId=';
$findme2 = '<span class="reward">';
$findme3 = '</span>';
// check if link is correct
$rightlink = strpos($link, $findme1);
// if link is correct
  if ($rightlink !== false)
{
    // get html from link
    $html = file($link);
    // iterate through html
    foreach ($html as $i => $line)
    {
        // set title
        if($i == 640) $title = htmlentities($line);
        // set requester
        if($i==669) $requester = htmlentities($line);
        if($i==678)
        {
            // modify the line and save as reward
            $line_modified = str_replace($findme2, '', $line);
            $line_modified = str_replace($findme3, '', $line_modified);
            $reward = htmlentities($line_modified);
        }
        // set qualifications
        if($i==711) $q = htmlentities($line);
    }

尝试PHP简单HTML DOM解析器,它会让你的生活变得轻松,阅读文档并做任何你想做的事情。如果你熟悉jQuery,那么你已经掌握它了。请看下面的例子

include('simple_html_dom.php');
$html = file_get_html('https://requester.mturk.com/');
foreach($html->find('a') as $link){
    echo $link . '<br />';
}

该代码从https://requester.mturk.com获取所有数据,并使用foreach循环打印所有链接。我认为代码是自我描述的