【问题标题】:fetching meta tags from many(like 10,000) URLs with PHP使用 PHP 从许多(如 10,000 个)URL 中获取元标记
【发布时间】:2015-04-20 00:34:44
【问题描述】:

我尝试从电子商务网站检索产品的元标记(例如 10,000 个)。该脚本有时有效,其余时间失败。我面临的错误是

致命错误:在...中的非对象上调用成员函数 find()

请提出更好的方法。

这是我正在使用的代码:

 $url = "http://www.amazon.com/dp/".$asin;
    $html = file_get_html( $url );
    $metatags = array();

foreach( $html->find( 'meta[name]' ) as $meta ) {
            $metatags[ 'meta' ][] = array(
            'name' => $meta->name,
            'content' => $meta->content
        );
    }

【问题讨论】:

  • 不要刮亚马逊,使用 API
  • 我正在使用 Amazon API,但找不到任何可以检索产品元标记的函数。如果有的话请给我建议。我也尝试过下面提到的教程,但我猜它没有说明元标记。

标签: php web-scraping find


【解决方案1】:

正如@Dagon 所说,这是使用亚马逊 API 的更好方法,此链接有一个 good tutorial in this topic

不管怎样,解决代码问题试试这个:

    $url = "http://www.amazon.com/dp/".$asin;
    $html = file_get_html( $url );
    $metatags = array();

    $names = array();
    try{
        $names = $html->find( 'meta[name]' );
    }
    catch(Exception $e)
    {
        error_log("Error: ".$e->getMessage());
    }

    foreach( $names as $meta ) {
            $metatags[ 'meta' ][] = array(
            'name' => $meta->name,
            'content' => $meta->content
        );
    }

【讨论】:

  • 我正在使用 Amazon API,但找不到任何可以检索产品元标记的函数。如果有的话请给我建议。
猜你喜欢
  • 2012-03-03
  • 1970-01-01
  • 2023-03-10
  • 2012-08-14
  • 2018-08-16
  • 1970-01-01
  • 2014-03-22
  • 1970-01-01
  • 2013-11-10
相关资源
最近更新 更多