【问题标题】:Scraping with simple.html.dom and placing the results into an array使用 simple.html.dom 抓取并将结果放入数组中
【发布时间】:2020-05-11 17:49:44
【问题描述】:

我不知道我的标题是否正确,请随时纠正我,但我有一个简单的问题。我的代码工作正常,我得到了我想要的结果,但我希望它们在一个数组中。例如:[0] => Description: Sentinel. Winged Guardian cannot have restricted attachments. Forced: After an attack in which Winged Guardian defends resolves, pay 1 Tactics resource or discard Winged Guardian from play.

[1] => Description: Attach to a hero. Attached hero gains +1 Attack. Action: Pay 1 resource from attached hero's pool to attach Dunedain Mark to another hero.

这是我的代码:

include 'simple_html_dom.php';

$url="http://hallofbeorn.com/LotR?CardSet=The+Hunt+for+Gollum";
$html=file_get_html($url);

   foreach ($html->find('div[style="margin-left:2px;vertical-align:top;text-align:left;"]') as $values) {
        echo $values->plaintext;
    }

【问题讨论】:

    标签: php web-scraping simple-html-dom


    【解决方案1】:

    我猜这就是你要找的东西:

    include 'simple_html_dom.php';
    
    $url="http://hallofbeorn.com/LotR?CardSet=The+Hunt+for+Gollum";
    $html=file_get_html($url);
    
    $html_arr = [];
    
    foreach ($html->find('div[style="margin-left:2px;vertical-align:top;text-align:left;"]') as $values) {
               $html_arr[] = $values->plaintext;
             }
    
    print_r($html_arr);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-31
      • 1970-01-01
      • 2014-02-08
      • 1970-01-01
      • 2014-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多