【问题标题】:How to find urls in images如何在图片中找到网址
【发布时间】:2011-03-21 05:41:44
【问题描述】:

我正在尝试从大量谷歌搜索结果中提取网址。从源代码中获取它们被证明是非常具有挑战性的,因为分隔符不明确,并且并非所有 url 都在代码中。是否有可以从图像的某个区域提取 url 的工具?如果是这样,那可能是一个更好的解决方案。

任何帮助将不胜感激。

【问题讨论】:

  • 图片如何在某些区域包含URL?你能给出一些你的意思的背景吗?这个问题是关于抓取谷歌图片搜索的吗?到目前为止,您尝试了什么?
  • 抓取 Google 违反了 Google 的 ToS
  • 您的意思是要从网页中提取图片网址?

标签: php html image screen-scraping


【解决方案1】:

尝试改用 JSON/Atom 自定义搜索 API:http://code.google.com/apis/customsearch/v1/overview.html。它每天为您提供 100 次 api 调用,如果您付费,您可以将其增加到每天 10000 次。

【讨论】:

    【解决方案2】:

    使用这个优秀的库:http://simplehtmldom.sourceforge.net/manual.htm

    // Grab the source code
    $html = file_get_html('http://www.google.com/');
    
    // Find all anchors, returns a array of element objects
    $ret = $html->find('a');
    
    // Get a attribute ( If the attribute is non-value attribute (eg. checked, selected...), it will returns true or false)
    $value = $ret->href;
    

    编辑:

    似乎所有“自然”搜索 url 都在 #res div 中。使用 simplehtmldom 找到第一个 #res,而不是其中的所有 url。不记得确切的语法,但它必须是这样的:

    $ret = $html->find('div[id=res]')->find('a'); 
    

    或许

    $html->find('div[id=res] a');
    

    【讨论】:

    • 不完全是。这是一个使用原生 DOM PHP 函数的 PHP 类,但使用起来更简单。
    • 我想区分付费搜索和自然搜索。找到所有的 url 不是问题,问题是找到付费搜索和自然搜索的 url。到目前为止,我一直在尝试使用爆炸,但谷歌代码中的分隔符很乱。有什么建议么? @CoBaLt2760 @Moshe
    • 所有“自然”搜索 url 似乎都在 #res div 中。使用 simplehtmldom 找到第一个 #res,而不是其中的所有 url。不记得确切的语法,但它必须是这样的: $ret = $html->find('div[id=res]')->find('a');或者 $html->find('div[id=res] a');
    猜你喜欢
    • 2017-10-31
    • 2018-08-07
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    • 2014-08-25
    • 1970-01-01
    • 2016-07-19
    • 2018-07-21
    相关资源
    最近更新 更多