簡體   English   中英

如何使用PHP DOM從href屬性獲取完整鏈接?

[英]How to get a full link from the href attribute using PHP DOM?

我正在嘗試解析此頁面上的鏈接。

我使用以下代碼:

$link = 'https://ws-na.assoc-amazon.com/widgets/cm?t=websitcom05-20&o=1&p=26&l=ur1&category=primeent&banner=1XSEYPQA2R6RS2D2B802&f=ifr';
$pageContent = file_get_contents($link);
$html = str_get_html($pageContent);

$body = $html->find('body', 0, true);

foreach ($body->find('area') as $area)
{
    echo $area->href;
}

輸出為http://rcm-na.amazon-adsystem.com/e/cm/privacy-policy.html?o=1 https://www.amazon.com

第二個鏈接被截斷。 請幫助我以獲取頁面的完整鏈接。

我需要以下輸出: https://www.amazon.com/gp/video/offers/ref=dvm_us_dd_as_evgrn?ie=UTF8&linkCode=ur1&redirectToAsin=B01EN8ZQKS&tag=INSERTSTOREID&tag=websitcom05-20 : https://www.amazon.com/gp/video/offers/ref=dvm_us_dd_as_evgrn?ie=UTF8&linkCode=ur1&redirectToAsin=B01EN8ZQKS&tag=INSERTSTOREID&tag=websitcom05-20

您似乎正在使用“ PHP簡單HTML DOM解析器”(位於: http : //simplehtmldom.sourceforge.net/

而不是完整的“ DOMDocument”,因此它可能會對在鏈接上處理的內容有所限制。

對於DOMDocument,在這里發現一個問題: 使用domDocument並解析信息,我想獲取'a'標簽的'href'內容

涵蓋獲取href

暫無
暫無

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

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