urlparse

how do i replace a query with a new value in urlparse?

本秂侑毒 提交于 2019-12-12 02:57:08
问题 so I have a data as follows: item = '//s780.scene7.com/is/image/forever/301596014_001?hei=98&wid=98' using urlparse module. how can i replace the above data with a new size to make it look like this: item = '//s780.scene7.com/is/image/forever/301596014_001?hei=360&wid=360' 回答1: Here is an answer which, as requested, uses urlparse: import urllib import urlparse url = '//s780.scene7.com/is/image/forever/301596014_001?hei=98&wid=98' parts = urlparse.urlparse(url) query_dict = urlparse.parse_qs

Reusing Spring RequestMapping parsing functionality

南笙酒味 提交于 2019-12-11 18:38:16
问题 I have some properties like /my/{custom}/url I would need to replace {custom} with some value at runtime I know that Spring is using "@RequestMapping" with a similar syntax for @PathAttribute matching. I'm wondering if there is some Class I can reuse from Spring to achieve what I need. 回答1: A good option for this is to use a UriComponentsBuilder - see reference here: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/util/UriComponentsBuilder.html

Python 3 : Why would you use urlparse/urlsplit [closed]

北慕城南 提交于 2019-12-11 10:17:05
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I'm not exactly sure what these modules are used for. I get that they split the respective url into its components, but why would that be useful, or what is an example of when to use urlparse? 回答1: Use urlparse only if you need parameter. I have explained below why do you need

Python urlparse: small issue

蓝咒 提交于 2019-12-10 23:58:48
问题 I'm making an app that parses html and gets images from it. Parsing is easy using Beautiful Soup and downloading of the html and the images works too with urllib2. I do have a problem with urlparse to make absolute paths out of relative ones. The problem is best explained with an example: >>> import urlparse >>> urlparse.urljoin("http://www.example.com/", "../test.png") 'http://www.example.com/../test.png' As you can see, urlparse doesn't take away the ../ away. This gives a problem when I

Modify URL components in Python 2

走远了吗. 提交于 2019-12-09 16:31:55
问题 Is there a cleaner way to modify some parts of a URL in Python 2? For example http://foo/bar -> http://foo/yah At present, I'm doing this: import urlparse url = 'http://foo/bar' # Modify path component of URL from 'bar' to 'yah' # Use nasty convert-to-list hack due to urlparse.ParseResult being immutable parts = list(urlparse.urlparse(url)) parts[2] = 'yah' url = urlparse.urlunparse(parts) Is there a cleaner solution? 回答1: Unfortunately, the documentation is out of date; the results produced

pythonic way to parse/split URLs in a pandas dataframe

孤街醉人 提交于 2019-12-08 02:43:30
问题 I have a df that has thousands of links like the ones below, for different users, in a column labeled url: https://www.google.com/something https://mail.google.com/anohtersomething https://calendar.google.com/somethingelse https://www.amazon.com/yetanotherthing I have the following code: import urlparse df['domain'] = '' df['protocol'] = '' df['domain'] = '' df['path'] = '' df['query'] = '' df['fragment'] = '' unique_urls = df.url.unique() l = len(unique_urls) i=0 for url in unique_urls: i+=1

pythonic way to parse/split URLs in a pandas dataframe

◇◆丶佛笑我妖孽 提交于 2019-12-06 06:18:09
I have a df that has thousands of links like the ones below, for different users, in a column labeled url: https://www.google.com/something https://mail.google.com/anohtersomething https://calendar.google.com/somethingelse https://www.amazon.com/yetanotherthing I have the following code: import urlparse df['domain'] = '' df['protocol'] = '' df['domain'] = '' df['path'] = '' df['query'] = '' df['fragment'] = '' unique_urls = df.url.unique() l = len(unique_urls) i=0 for url in unique_urls: i+=1 print "\r%d / %d" %(i, l), split = urlparse.urlsplit(url) row_index = df.url == url df.loc[row_index,

How can I prepend the 'http://' protocol to a url when necessary? [duplicate]

只愿长相守 提交于 2019-12-05 12:56:27
问题 This question already has answers here : How can I prepend http to a url if it doesn't begin with http? (4 answers) Closed last year . I need to parse an URL. I'm currently using urlparse.urlparse() and urlparse.urlsplit(). The problem is that i can't get the "netloc" (host) from the URL when it's not present the scheme. I mean, if i have the following URL: www.amazon.com/Programming-Python-Mark-Lutz/dp/0596158106/ref=sr_1_1?ie=UTF8&qid=1308060974&sr=8-1 I can't get the netloc: www.amazon.com

Modify URL components in Python 2

懵懂的女人 提交于 2019-12-04 03:36:28
Is there a cleaner way to modify some parts of a URL in Python 2? For example http://foo/bar -> http://foo/yah At present, I'm doing this: import urlparse url = 'http://foo/bar' # Modify path component of URL from 'bar' to 'yah' # Use nasty convert-to-list hack due to urlparse.ParseResult being immutable parts = list(urlparse.urlparse(url)) parts[2] = 'yah' url = urlparse.urlunparse(parts) Is there a cleaner solution? Martijn Pieters Unfortunately, the documentation is out of date; the results produced by urlparse.urlparse() (and urlparse.urlsplit() ) use a collections.namedtuple() -produced

How can i import urlparse in python-3? [duplicate]

那年仲夏 提交于 2019-12-03 14:33:37
问题 This question already has answers here : no module named urllib.parse (How should I install it?) (11 answers) Closed last year . I would like to use urlparse . But python3.4.1 is not finding the module. I do import urlparse , but it gives me this error importError: no 'module' named ulrparse 回答1: The urlparse in Python 2.7.11 was renamed to urllib.parse in Python 3. So, if you have a code such from urlparse import urljoin , I suggest you change it to from urllib.parse import urljoin 回答2: As