Questions tagged [url-parsing]

URL parsing is the process of taking a URL and producing a representation of its constituent parts: scheme, host, port, path, query, and fragment. The URL Standard defines an algorithm for URL parsing.

See https://url.spec.whatwg.org/#url-parsing

166 questions
443
votes
34 answers

How to convert URL parameters to a JavaScript object?

I have a string like this: abc=foo&def=%5Basf%5D&xyz=5 How can I convert it into a JavaScript object like this? { abc: 'foo', def: '[asf]', xyz: 5 }
Alex
  • 66,732
  • 177
  • 439
  • 641
262
votes
12 answers

How can I get parameters from a URL string?

I have an HTML form field $_POST["url"], having some URL strings as the value. Example values…
Asim Zaidi
  • 27,016
  • 49
  • 132
  • 221
240
votes
32 answers

Change URL parameters and specify defaults using JavaScript

I have this URL: site.fwx?position=1&archiveid=5000&columns=5&rows=20&sorting=ModifiedTimeAsc what I need is to be able to change the 'rows' url param value to something i specify, lets say 10. And if the 'rows' doesn't exist, I need to add it to…
Sindre Sorhus
  • 62,972
  • 39
  • 168
  • 232
81
votes
4 answers

Creating a new Location object in javascript

Is it possible to create a new Location object in javascript? I have a url as a string and I would like to leverage what javascript already provides to gain access to the different parts of it. Here's an example of what I'm talking about (I know…
Josh Johnson
  • 10,729
  • 12
  • 60
  • 83
80
votes
4 answers

Get integer value from malformed query string

I'm looking for an way to parse a substring using PHP, and have come across preg_match however I can't seem to work out the rule that I need. I am parsing a web page and need to grab a numeric value from the string, the string is like…
MonkeyBlue
  • 2,234
  • 6
  • 31
  • 41
51
votes
9 answers

Is $_SERVER['REQUEST_SCHEME'] reliable?

I recently was seeking a way to properly determine protocol, under which url request was supplied to the server. I watched through parse_url() and though $_SERVER superglobal variable, and found this:
BlitZ
  • 12,038
  • 3
  • 49
  • 68
28
votes
9 answers

How to get the last path in a URL?

I would like get the last path segment in a URL: http://blabla/bla/wce/news.php or http://blabla/blablabla/dut2a/news.php For example, in these two URLs, I want to get the path segment: 'wce', and 'dut2a'. I tried to use $_SERVER['REQUEST_URI'],…
bahamut100
  • 1,795
  • 7
  • 27
  • 38
26
votes
2 answers

Reconstructing absolute urls from relative urls on a page

Given an absolute url of a page, and a relative link found within that page, would there be a way to a) definitively reconstruct or b) best-effort reconstruct the absolute url of the relative link? In my case, I'm reading an html file from a given…
Yarin
  • 173,523
  • 149
  • 402
  • 512
25
votes
14 answers

How can I extract video ID from YouTube's link in Python?

I know this can be easily done using PHP's parse_url and parse_str functions: $subject = "http://www.youtube.com/watch?v=z_AbfPXTKms&NR=1"; $url = parse_url($subject); parse_str($url['query'], $query); var_dump($query); But how to achieve this…
decarbo
  • 347
  • 1
  • 5
  • 17
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
18
votes
5 answers

Python: Join multiple components to build a URL

I am trying to build a URL by joining some dynamic components. I thought of using something like os.path.join() BUT for URLs in my case. From research I found urlparse.urljoin() does the same thing. However, it looks like it only take two arguments…
summerNight
  • 1,446
  • 3
  • 25
  • 52
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
16
votes
2 answers

How to remove subdomains from domains using javascript

I am starting with domains that look like this: www.exemple.com main.testsite.com www.ex-emple.com.ar main.test-site.co.uk en.tour.mysite.nl www.ip.com www.one.lv and I need to remove the subdomains to get values that look like…
usr13
  • 161
  • 1
  • 4
15
votes
3 answers

URL parsing in Java

I've got the URL like this: http://test.com/testapp/test.do?test_id=1&test_name=SS Is there any way we can get only this part /test.do?test_id=1&test_name=SS
user2346047
  • 213
  • 1
  • 2
  • 16
14
votes
1 answer

Why is / an invalid path when /a is valid?

I’m trying to understand why certain HTML attributes are failing W3C validation. I encountered this in a real codebase, but here’s a minimal reproduction: a 1
ændrük
  • 782
  • 1
  • 8
  • 22
1
2 3
11 12