doujiu3882 2012-01-15 22:46
浏览 62
已采纳

通过PHP从Google新闻RSS获取实际链接

I want to parse Google News RSS with PHP, to get actual links of the content.

Google News RSS item link looks like this:

http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNGkF58EwDE7aA742GfVP9aE8azmhg&url=http://www.reuters.com/article/2012/01/15/us-obama-mlk-idUSTRE80E0PD20120115

I need just the actual link, everything after &url= :

http://www.reuters.com/article/2012/01/15/us-obama-mlk-idUSTRE80E0PD20120115

And how would one go about eliminating the "non-essential" part of the URL, in essence targeting everything starting with http://news.google.com and ending with &url= ?

http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNGkF58EwDE7aA742GfVP9aE8azmhg&url=

I do a little regex, but this is out of my reach...

Thanks, fellas!

  • 写回答

2条回答 默认 最新

  • dqunzip3183 2012-01-15 23:05
    关注

    Regex is not necessarily the best approach here.

    $query = parse_url($google_url, PHP_URL_QUERY);
    parse_str($query, $parts);
    $url = $parts['url'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度