【问题标题】:How to get a full link from the href attribute using PHP DOM?如何使用 PHP DOM 从 href 属性中获取完整链接?
【发布时间】:2019-04-14 09:13:16
【问题描述】:

我正在尝试解析来自this page 的链接。

我使用这个代码:

$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

【问题讨论】:

    标签: php html dom href file-get-contents


    【解决方案1】:

    您似乎在使用“PHP Simple HTML DOM Parser”(位于:http://simplehtmldom.sourceforge.net/

    不是完整的“DOMDocument”,因此它可能会对链接上的处理内容有所限制。

    对于 DOMDocument,这里有一个问题: Using domDocument, and parsing info, I would like to get the 'href' contents of an 'a' tag

    这包括获取 href

    【讨论】:

      猜你喜欢
      • 2021-12-25
      • 2011-02-08
      • 2023-03-12
      • 2015-08-30
      • 2011-05-21
      • 2015-05-30
      • 2019-12-23
      • 1970-01-01
      • 2017-05-28
      相关资源
      最近更新 更多