- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不太确定这些模块的用途。我知道他们将各自的 url 拆分为其组件,但是为什么这会有用,或者什么时候使用 urlparse 的示例是什么?
最佳答案
仅当需要参数时才使用urlparse
。我在下面解释了为什么需要参数。
urllib.parse.urlsplit(urlstring, scheme='', allow_fragments=True)
This is similar to urlparse(), but does not split the params from theURL. This should generally be used instead of urlparse() if the morerecent URL syntax allowing parameters to be applied to each segment ofthe path portion of the URL (see RFC 2396) is wanted.
主机名对于存储在变量中以便稍后使用或添加参数、查询主机名以在抓取时获取您想要的网页总是有用的。
关于参数:
仅供引用:根据 RFC2396,url 中的参数
Extensive testing of current client applications demonstrated that themajority of deployed systems do not use the ";" character to indicatetrailing parameter information, and that the presence of a semicolonin a path segment does not affect the relative parsing of thatsegment. Therefore, parameters have been removed as a separatecomponent and may now appear in any path segment. Their influence hasbeen removed from the algorithm for resolving a relative URIreference.
参数在抓取时很有用,例如如果网址为 http://www.example.com/products/women?color=green
当你使用urlparse
时,你会得到参数。现在您必须将其更改为 men
,这样它将是 http://www.example.com/products/men?color=green
和 kids
、女孩
、男孩
等等。
关于python-3.4 - Python 3 : Why would you use urlparse/urlsplit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30091297/
登录网站后我想收集它的链接。这是我用这个函数做的(使用 mechanize 和 urlparse 库): br = mechanize.Browser() . . #logging in on web
我无法运行此代码,有人可以帮助我吗? import sys, urllib, re, urlparse from urllib import urlretrieve from BeautifulSou
我试图弄清楚为什么我会看到错误 ModuleNotFoundError: No module named 'urlparse'但我从不在我的代码中调用 urlparse。当我尝试使用 pip 安装 u
如果缺少“http”方案名称,我想在给定的 url 字符串前面添加它。否则,不要管 url,所以我认为 urlparse 是执行此操作的正确方法。但是每当没有方案并且我使用 get url 时,我会在
我在使用 https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-python 中的以下代码行时遇到问题 impor
我有两个系统: 第一个按预期工作: >>> urlparse.urlparse('foo://bar/?blu=1') ParseResult(scheme='foo', netloc='bar',
我正在尝试用 python 分隔 url 的不同部分s urlparse,但我似乎在结果中得到了错误的值。 baseline = runSql(conn,"Select url from malwar
我想知道是否有已知的解决方法来解决我在 python 的 urlparse 中看到的一些奇怪行为。 以下是 python 解释器中几行的一些结果: >>> import urlparse >>> ur
Python 的 urlparse 函数将 url 解析为六个部分(方案、netloc、路径和其他东西) 现在我发现解析“example.com/path/file.ext”不返回 netloc,而是
在Python的urlparse中,可以使用urlparse解析URL,然后parse_qsl解析query。 我想删除一个查询(名称、值)对,然后重建 URL。 有urlunparse方法,没有un
需要一种使用 Python urlparse 从 url 中提取不带子域的域名的方法。 例如,我想从 "http://www.google.com" 之类的完整网址中提取 "google.com"。
1、简介 urlparse模块用户将url解析为6个组件,并以元组形式返回,返回的6个部分,分别是:scheme(协议)、netloc(网络位置)、path(路径)、params(路径段参数)、
所以我有一个数据如下: item = '//s780.scene7.com/is/image/forever/301596014_001?hei=98&wid=98' 使用 urlparse 模块。
我正在制作一个解析 html 并从中获取图像的应用程序。使用 Beautiful Soup 可以轻松解析并下载 html,图像也可以使用 urllib2。 我确实在 urlparse 中遇到问题,无法
在从相对目录构造绝对 URL 时,是否有一种方法可以解决“无效”父目录的问题,还是我应该只使用 .replace()? >>> from urlparse import urljoin >>> url
这段简单的代码使 urlparse 变得疯狂,它没有正确获取主机名,而是将其设置为 None: from urllib.parse import urlparse parsed = urlparse(
其中URL parsing function pair我应该使用,为什么? urlparse和 urlunparse , 或 urlsplit和 urlunsplit ? 最佳答案 直接来自 the
当netloc为空时urlparse.urlunparse不一致: >>> urlparse.urlunparse(('http','','test_path', None, None, None))
我有以下代码,用于检查输入的 url 是否有效: #!/usr/bin/env python3 import sys import urllib.parse # ... def checkValidU
urlparse.parse_qs 对于解析 url 参数很有用,它可以很好地处理简单的 ASCII url,用 str 表示。所以我可以解析一个查询,然后使用 urllib.urlencode 从解
我是一名优秀的程序员,十分优秀!