簡體   English   中英

DOM Scrape無法正常工作的PHP

[英]DOM Scrape not working PHP

我只是想知道為什么這對我不起作用。 我想要做的是刪除m4v文件。 我的網站上有一個類似的腳本用於處理圖像,該腳本將剝離圖像,然后將其上傳到目錄和數據庫並進行鏈接。 但是我不能以相同的方式來工作。 謝謝你的幫助

<?php

include('simple_html_dom.php');

$html = file_get_html("http://www.mysitesvids.com/m/videos/view/36821");
$element = $html->find("file:");
$result = $element->innertext;

?>

這是網站上的代碼

<script type="text/javascript" language="javascript">
jwplayer ('embedFlashPlayer').setup         ({flashplayer:'/swf/jwplayer5.swf',id:'moviePlayer',width:602,height:404,
    file:'http://davesvideos.mysitevids.com/media/b0e9ec18eb567ce41dce906cee7e1c9f/4fcbb164/videos/m/634276.m4v',
image:'/media/80eb2eaca3c58f002be8ab5bda476e91/4fcbb164/videos/p/64/634276.jpg',
provider:'http',controlbar:'bottom',stretching:'uniform',abouttext:'mysite',aboutlink:'http://www.eroprofile.com/'});

glbUpdViews ('0','634276','0','0');
ajaxActive = false;
cmtLoad ('video', '634276', '', '');
ajaxActive = false;
cmtReply ('video', '634276', '0');


</script>

從SimpleHtmlDom的文檔中, find()僅匹配html元素,因此您無法使用find()搜索“ file:”,您可以執行以下操作:

$script = $html->find('script')->innertext

並應用正則表達式以匹配$script上的* .mv4文件。

或者,您可以將正則表達式匹配直接應用於文件的內容。

使用正則表達式可以更輕松地解決此問題:

preg_match( "/file:'(.+?)'/", $html, $matches );

if ( $matches ) {
    echo $matches[1];
}

我假設您在頁面上沒有此字符串模式的其他實例。 如果這樣做,並且只想匹配m4v,則可以修改表達式以查找該擴展名:

preg_match( "/file:'(.+?\.m4v)'/", $html, $matches );

if ( $matches ) {
    echo $matches[1];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM