简体   繁体   中英

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

I am trying to parse links from this page .

I use this code:

$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;
}

The output is http://rcm-na.amazon-adsystem.com/e/cm/privacy-policy.html?o=1 https://www.amazon.com

The second link is truncated. Please help me out to get the full link from the page.

I need to have this output: https://www.amazon.com/gp/video/offers/ref=dvm_us_dd_as_evgrn?ie=UTF8&linkCode=ur1&redirectToAsin=B01EN8ZQKS&tag=INSERTSTOREID&tag=websitcom05-20

You appear to be using "PHP Simple HTML DOM Parser" (found at: http://simplehtmldom.sourceforge.net/ )

not the full fat "DOMDocument" so it might have limits on what it can process on links.

for DOMDocument there is a question found here: Using domDocument, and parsing info, I would like to get the 'href' contents of an 'a' tag

that covers getting the href

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM