使用Python 内置的模块 urlparse

from urlparse import *
url = 'https://docs.google.com/spreadsheet/ccc?key=blah-blah-blah-blah#gid=1'
result = urlparse(url)

result 包含了URL的所有信息

>>> from urlparse import *
>>> url = 'https://docs.google.com/spreadsheet/ccc?key=blah-blah-blah-blah#gid=1'
>>> result = urlparse(url)
>>> print result
ParseResult(scheme='https', netloc='docs.google.com', path='/spreadsheet/ccc', params='', query='key=blah-blah-blah-blah', fragment='gid=1')
>>> url='http://pkunews.pku.edu.cn/xwzh/2018-04/29/content_302272.htmhttp://pkunews.pku.edu.cn/xwzh/2018-04/29/content_302272.htm'
>>> result = urlparse(url)
>>> print result
ParseResult(scheme='http', netloc='pkunews.pku.edu.cn', path='/xwzh/2018-04/29/content_302272.htmhttp://pkunews.pku.edu.cn/xwzh/2018-04/29/content_302272.htm', params='', query='', fragment='')

python 从url中提取域名和path的更多相关文章

  1. 【C++】获取URL中主机域名

    // ConsoleApplication1.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <windows.h& ...

  2. python处理url中的中文编码,以及其他编码问题

    1.python中的urlencode与urldecode 2.各种编码转换在线工具 3.python用于url解码和中文解析的小脚本(python url decoder) 4.如何只对url中的中 ...

  3. python 从给定的URL中提取顶级域名(TLD)

    安装 PyPI的最新稳定版本: pip install tld 或者GitHub的最新稳定版本: pip install https://github.com/barseghyanartur/tld/ ...

  4. [译]使用BeautifulSoup和Python从网页中提取文本

    如果您要花时间浏览网页,您可能遇到的一项任务就是从HTML中删除可见的文本内容. 如果您使用的是Python,我们可以使用BeautifulSoup来完成此任务. 设置提取 首先,我们需要获取一些HT ...

  5. python 从视频中提取图片,并保存在硬盘上

    使用python的moviepy库来提取视频中的图片,按照视频每帧一个图片的方式来保存. extract images from video, than save them to disk from ...

  6. 从一个标准URL中提取文件的扩展名

    例如:http://www.sina.cn/abc/de.php?id=1  提出php 1. $url = 'http://www.sina.cn/abc/de.php?id=1'; $arr = ...

  7. 从url中提取参数名和参数值(转)

    在已知参数名的情况下,获取参数值,使用正则表达式能很容易做到.js的实现方法如下: function getValue(url, name) { var reg = new RegExp('(\\?| ...

  8. 替换url中的域名

    /**     *      * @param domain 域名     * @param port   端口号     * @param url    url路径     * @return   ...

  9. python从文本中提取某酒店机顶盒号和智能卡号

    1.某项目中经常遇到需要关闭一些机顶盒消费权限.但是给过来的不是纯字符串,需要自己提取. 有400多个机顶盒和智能卡.nodepad++的列块模式也可以提取,但是还是稍微麻烦,因为列不对等 先复制到文 ...

随机推荐

  1. 64. Minimum Path Sum(最小走棋盘 动态规划)

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...

  2. rmp-st算法

    struct RMQ { ]; void init(int n) { ; i <= n; i ++)log2[i] = (i == ? - : log2[i >> ] + ); ; ...

  3. hdu3518 Boring counting

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=3518 题目: Boring counting Time Limit: 2000/1000 MS ...

  4. myeclipse自动生成相应对象接收返回值的快捷键

    在你要自动生成返回值对象的那一行的末尾(注意一定要将光标点到最后),按Alt+Shift+L:就可以了.

  5. Object类包含方法

    9个方法: 1. clone() 2. equals() 3. finalize() 4. getClass() 5. notify() 6. notifyAll() 备注:5.6多归于一个 7. h ...

  6. Java 设计模式六原则及23中常用设计模式

    一.设计模式的分类 总体来说设计模式分为三大类: 创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. 结构型模式,共七种:适配器模式.装饰器模式.代理模式.外观模式.桥接 ...

  7. MR案例:Reduce-Join

    问题描述:两种类型输入文件:address(地址)和company(公司)进行一对多的关联查询,得到地址名(例如:Beijing)与公司名(例如:Beijing JD.Beijing Red Star ...

  8. openwrt设置uboot环境变量在flash上的存储地址

    1.分析如下 ubootenv_add_app_config ubootenv_add_uci_config "/dev/mtd1" "0x40000" &qu ...

  9. HikariPool-1 - Exception during pool initialization.

    java.sql.SQLNonTransientConnectionException: CLIENT_PLUGIN_AUTH is required 这是由于springboot自带 mysql-c ...

  10. parted 分区

    Linux下的GPT分区 GPT分区 这是另外一种分区,针对MBR分区,它有很多优点: (1)几乎突破了分区个数的限制. 在GPT分区表中最多可以支持128个主分区. (2)单个分区容量几乎没有限制. ...