我正試圖從這個 div 中獲取albumid's value (20316543),但我似乎無法想出一種方法來做到這一點......這就是我到目前為止所擁有的。$file = file_get_contents('https://somesite.com');$dom = new DomDocument;$dom->loadHTMLFile($file);$xpath = new DomXPath($dom);$data = $xpath->query("//div[@class='play']");$ttt = $dom->saveHTML($data);print_r($data);html代碼<div class="overlay-actions"> <div class="overlay-action-buttons"> <button class="play" onclick="Analytics.logAndSendEventToGA('album:play-all',['albumid','20316543']);Content.playAllSongs('#play-2020', true, 0, true);">Play</button> </div> </div>
1 回答

拉丁的傳說
TA貢獻(xiàn)1789條經(jīng)驗 獲得超8個贊
可能還有其他方法可以做同樣的事情,但試試這個:
$string = <<<XML
[your html snippet]
XML;
$xml = simplexml_load_string($string);
$result = $xml->xpath("//div//div/button/@onclick");
$left = explode (",[",$result[0])[1];
$target = explode("])",$left)[0];
echo ($target);
輸出:
'albumid','20316543'
- 1 回答
- 0 關(guān)注
- 179 瀏覽
添加回答
舉報
0/150
提交
取消