Questions tagged [urlparse]

urlparse is used for parsing a URL into components like (addressing scheme, network location, path etc.)

urlparse is module in Python2.7 and renamed to urllib.parse in Python 3

Links:

urlparse

urllib.parse

196 questions
92
votes
12 answers

How to extract a filename from a URL and append a word to it?

I have the following URL: url = http://photographs.500px.com/kyle/09-09-201315-47-571378756077.jpg I would like to extract the file name in this URL: 09-09-201315-47-571378756077.jpg Once I get this file name, I'm going to save it with this name to…
deadlock
  • 7,048
  • 14
  • 67
  • 115
73
votes
2 answers

How can I import urlparse in python-3?

I would like to use urlparse, but Python 3 is not finding the module. I do import urlparse, but it gives me this error ImportError: no 'module' named urlparse
Mohamed Mahdi
  • 1,286
  • 3
  • 11
  • 13
56
votes
7 answers

Python urlparse -- extract domain name without subdomain

Need a way to extract a domain name without the subdomain from a url using Python urlparse. For example, I would like to extract "google.com" from a full url like "http://www.google.com". The closest I can seem to come with urlparse is the netloc…
Clay Wardell
  • 14,846
  • 13
  • 44
  • 65
55
votes
9 answers

How do you strip out the domain name from a URL in php?

Im looking for a method (or function) to strip out the domain.ext part of any URL thats fed into the function. The domain extension can be anything (.com, .co.uk, .nl, .whatever), and the URL thats fed into it can be anything from…
user15063
49
votes
1 answer

What are the URL parameters? (element at position #3 in urlparse result)

I've taken a look to urlparse.urlparse method documentation and I'm a little bit confused about what is the parameters part (not to be confused with the more familiar query part, that is what goes after the question mark and before the fragment…
fortran
  • 74,053
  • 25
  • 135
  • 175
42
votes
3 answers

Which should I be using: urlparse or urlsplit?

Which URL parsing function pair should I be using and why? urlparse and urlunparse, or urlsplit and urlunsplit?
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
37
votes
3 answers

Best way to get query string from a URL in python?

I need to get the query string from this URL https://stackoverflow.com/questions/ask?next=1&value=3 and I don't want to use request.META. I have figured out that there are two more ways to get the query string: Using…
NIlesh Sharma
  • 5,445
  • 6
  • 36
  • 53
34
votes
8 answers

How do I remove a query string from URL using Python

Example: http://example.com/?a=text&q2=text2&q3=text3&q2=text4 After removing "q2", it will return: http://example.com/?q=text&q3=text3 In this case, there were multiple "q2" and all have been removed.
user990611
  • 351
  • 1
  • 3
  • 4
31
votes
3 answers

"No module named 'urlparse'" but I'm not using urlparse

I'm trying to figure out why I am seeing an error ModuleNotFoundError: No module named 'urlparse' but I never call urlparse in my code. When I try to install urlparse with pip, I am seeing that this module doesn't exist. When I try to install…
mnickey
  • 727
  • 1
  • 6
  • 15
30
votes
5 answers

Is there a predefined class for URL in Python?

I am looking for something like java.net.URL in python-modules, Django, Zope or wherever in Python. I want it preferably from the semantics reason, because the result of analysis of concerned program implies that the URL plays an essential role in…
sumid
  • 1,871
  • 2
  • 25
  • 37
22
votes
6 answers

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

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…
santiagobasulto
  • 11,320
  • 11
  • 64
  • 88
22
votes
1 answer

Parse query part from url

I want to parse query part from url, this is my code to do this: >>> from urlparse import urlparse, parse_qs >>> url = '/?param1¶m2=2' >>> parse_qs(urlparse(url).query) >>> {'param2': ['23']} This code looks good, but "parse_qs" method loses…
Gr1N
  • 1,337
  • 3
  • 14
  • 19
17
votes
4 answers

Python script to see if a web page exists without downloading the whole page?

I'm trying to write a script to test for the existence of a web page, would be nice if it would check without downloading the whole page. This is my jumping off point, I've seen multiple examples use httplib in the same way, however, every site I…
some1
  • 2,447
  • 8
  • 26
  • 23
16
votes
4 answers

How to change values of url query in python?

url = "http://www.example.com?type=a&type1=b&type2=c" urllist = get_urllist(url) trigger = ["'or '1'='1'"," 'OR '1'='2'","'OR a=a"] def get_urllist(url): url_parsed = urlparse.urlparse(url) #extract the query parameters of the URL …
Anubhav Singh
  • 432
  • 1
  • 5
  • 15
15
votes
4 answers

Split a URL into its components in Python

I have a huge list of URLs that are all like this: http://www.example.com/site/section1/VAR1/VAR2 Where VAR1 and VAR2 are the dynamic elements of the URL. I want to extract only the VAR1 from this URL string. I've tried to use urlparse, but the…
Hyperion
  • 2,515
  • 11
  • 37
  • 59
1
2 3
13 14