簡體   English   中英

simplehtmldom-限制get_html的內容大小?

[英]Simplehtmldom - limit content size for get_html?

我正在使用simplehtmldom獲取某些鏈接的標題,並且想知道是否可以限制下載內容的大小? 無需下載整個內容,只需下載前20行代碼即可獲得標題。

現在我正在使用這個:

  $html = file_get_html($row['current_url']);

  $e = $html->find('title', 0);
  $title = $e->innertext;
  echo $e->innertext . '<br><br>';

謝謝

除非我錯過了一些東西,否則file_get_html不會那樣工作。 它將檢索頁面的內容。

換句話說,它必須閱讀整個頁面才能在下一部分中找到所需內容。

現在,如果您要使用:

$section = file_get_contents('http://www.the-URL.com/', NULL, NULL, 0, 444);

只要您獲得的頁面從<!DOCTYPE html></head><body><title></title>始終相同,就可以隔離html的前20行。

然后,只要Head的數量相同,就可以抓住前20行左右。

然后使用:

$html = str_get_html($section);

然后從那里使用“查找”

$html->find('title', 0);


編輯:

 include('simple_html_dom.php'); $the_url = 'http://www.the-URL.com/'; // Read 444 characters starting from the 1st character $section = file_get_contents($the_url, NULL, NULL, 0, 444); $html = str_get_html($section); if (!$e = $html->find('title', 0)) { // Read 444 characters starting from the 445th character $section = file_get_contents($the_url, NULL, NULL, 444, 888); $html = str_get_html($section); $e = $html->find('title', 0); } $title = $e->innertext; echo $title . '<br><br>'; 

暫無
暫無

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

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