简体   繁体   中英

Scraping with simple.html.dom and placing the results into an array

i don't know if my title is correct feel free to correct me, but i have a simple issue. My code is working fine and i am getting the results that i want, but i want them in an array. For example: [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. [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.

This is my code:

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

I guess this is what you are looking for:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM