ruby类库URI解析url时的错误 split': bad URI(is not URI?)
编程技术  /  houtizong 发布于 3年前   121
url = "http://v.t.sina.com.cn/share/share.php?source=viviband&title=%E7%9C%8B%E5%88%B0%E4%B8%80%E5%BC%BA%E5%8A%9B%E7%9A%84%E5%9B%BE%2C%E6%B1%82%E6%AD%A4%E5%AE%8F%E5%A6%82%E4%BD%95%E5%81%9A%20-%20%E8%89%BE%E6%B3%BD%E6%8B%89%E6%96%AF%E5%9B%BD%E5%AE%B6%E5%9C%B0%E7%"
URI.parse(url)
URI::InvalidURIError: bad URI(is not URI?): http://v.t.sina.com.cn/share/share.php?source=viviband&title=%E7%9C%8B%E5%88%B0%E4%B8%80%E5%BC%BA%E5%8A%9B%E7%9A%84%E5%9B%BE%2C%E6%B1%82%E6%AD%A4%E5%AE%8F%E5%A6%82%E4%BD%95%E5%81%9A%20-%20%E8%89%BE%E6%B3%BD%E6%8B%89%E6%96%AF%E5%9B%BD%E5%AE%B6%E5%9C%B0%E7%
URI.parse(url.split("?")[0]).host
URI.parse(URI.encode(url)).host
>> URI.encode(url)=> "http://v.t.sina.com.cn/share/share.php?source=viviband&title=%25E7%259C%258B%25E5%2588%25B0%25E4%25B8%2580%25E5%25BC%25BA%25E5%258A%259B%25E7%259A%2584%25E5%259B%25BE%252C%25E6%25B1%2582%25E6%25AD%25A4%25E5%25AE%258F%25E5%25A6%2582%25E4%25BD%2595%25E5%2581%259A%2520-%2520%25E8%2589%25BE%25E6%25B3%25BD%25E6%258B%2589%25E6%2596%25AF%25E5%259B%25BD%25E5%25AE%25B6%25E5%259C%25B0%25E7%25"
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接