0

名前で要素を取得するために単純なdomを使用しようとしています

古いウェブサイトをクロールするためのもので、名前だけを使用しています

<select name="id_items_1" required="">
    <option value="">Seleccione su talla</option>
    <option value="231085" data-talla="36" data-stock="3">36</option>
    <option value="231086" data-talla="37" data-stock="1">37</option>
</select>

私はこれを試しましたが、nullを返します:

include('simple_html_dom.php');
$html = str_get_html($url);
$elem = $html->find('div[name=id_items_1]', 0);
var_dump($elem);

単純なdomでこれを行う方法はありますか?

4

2 に答える 2

1

file_get_contentsリモート URL の html を取得するために最初に呼び出してselect[name=id_items_1] optionから、セレクターを見つけるために使用する必要があります。

include('simple_html_dom.php');
$html = str_get_html(file_get_contents($url));
$elem = $html->find('select[name=id_items_1] option', 0);
var_dump($elem);
于 2016-07-19T03:55:15.340 に答える
1

URL に変更しfile_get_htmlて追加する必要がありますhttp://

include('simple_html_dom.php'); 
$url="http://platanitos.com/Platanitos-ZC-LUCY-161-Negro-49272";; 
$html = file_get_html($url); 
$elem = $html->find('select[name=id_items_1]', 0)->innertext; 
var_dump($elem);
于 2016-07-19T04:03:59.410 に答える