url-parsing

Get second level domain name from URL

自作多情 提交于 2019-12-09 09:37:33
问题 Is there a way to get top level domain name from the url for e.g., "https://images.google.com/blah" => "google" I found this: var domain = new URL(pageUrl).hostname; but it gives me "images.google.com" instead of just google. Unit tests I have are: https://images.google.com => google https://www.google.com/blah => google https://www.google.co.uk/blah => google https://www.images.google.com/blah => google 回答1: You could do this: location.hostname.split('.').pop() EDIT Saw the change to your

A Delphi/FreePascal lib or function that emulates the PHP's function parse_url

半腔热情 提交于 2019-12-08 22:34:19
问题 I'm doing a sitemap producer in Object Pascal and need a good function or lib to emulate the parse_url function on PHP. Does anyone know of any good ones? 回答1: Freepascal has the unit URIParser with the ParseURI function. An example how to use it can be found in one of the example in Freepascal's source. Or an old example which is somewhat easier to understand. 回答2: I am not familiar with the parse_url function on PHP, but you might try the TIdURI class that is included with Indy (which in

window.location.hash issue in Firefox

£可爱£侵袭症+ 提交于 2019-12-07 05:21:16
问题 Consider the following code: hashString = window.location.hash.substring(1); alert('Hash String = '+hashString); When run with the following hash: #car=Town%20%26%20Country the result in Chrome and Safari will be: car=Town%20%26%20Country but in Firefox (Mac AND PC) will be: car=Town & Country Because I use the same code to parse query and hash params: function parseParams(paramString) { var params = {}; var e, a = /\+/g, // Regex for replacing addition symbol with a space r = /([^&;=]+)=?([^

How can multiple trailing slashes can be removed from a URL in Ruby

倾然丶 夕夏残阳落幕 提交于 2019-12-07 01:28:04
问题 What I'm trying to achieve here is lets say we have two example URLs: url1 = "http://emy.dod.com/kaskaa/dkaiad/amaa//////////" url2 = "http://www.example.com/" How can I extract the striped down URLs? url1 = "http://emy.dod.com/kaskaa/dkaiad/amaa" url2 = "http://http://www.example.com" URI.parse in Ruby sanitizes certain type of malformed URL but is ineffective in this case. If we use regex then /^(.*)\/$/ removes a single slash / from url1 and is ineffective for url2 . Is anybody aware of

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

window.location.hash issue in Firefox

六眼飞鱼酱① 提交于 2019-12-05 10:24:47
Consider the following code: hashString = window.location.hash.substring(1); alert('Hash String = '+hashString); When run with the following hash: #car=Town%20%26%20Country the result in Chrome and Safari will be: car=Town%20%26%20Country but in Firefox (Mac AND PC) will be: car=Town & Country Because I use the same code to parse query and hash params: function parseParams(paramString) { var params = {}; var e, a = /\+/g, // Regex for replacing addition symbol with a space r = /([^&;=]+)=?([^&;]*)/g, d = function (s) { return decodeURIComponent(s.replace(a, " ")); }, q = paramString; while (e

How can multiple trailing slashes can be removed from a URL in Ruby

可紊 提交于 2019-12-05 04:17:18
What I'm trying to achieve here is lets say we have two example URLs: url1 = "http://emy.dod.com/kaskaa/dkaiad/amaa//////////" url2 = "http://www.example.com/" How can I extract the striped down URLs? url1 = "http://emy.dod.com/kaskaa/dkaiad/amaa" url2 = "http://http://www.example.com" URI.parse in Ruby sanitizes certain type of malformed URL but is ineffective in this case. If we use regex then /^(.*)\/$/ removes a single slash / from url1 and is ineffective for url2 . Is anybody aware of how to handle this type of URL parsing? The point here is I don't want my system to have http://www

Get page URL parameters from a service worker

旧街凉风 提交于 2019-12-04 18:15:09
How do I get page URL with parameters from a service worker? I have tried self.registration.scope but that doesn't include the parameters. I'm not clear as to whether you're asking about getting the service worker script's URL, or the URLs of all of the client pages that are open under the service worker's scope. So... here's how to do both: // Get a URL object for the service worker script's location. const swScriptUrl = new URL(self.location); // Get URL objects for each client's location. self.clients.matchAll({includeUncontrolled: true}).then(clients => { for (const client of clients) {

Break up/parse a URL into its constituent parts in php

孤街浪徒 提交于 2019-12-02 20:08:12
问题 What is the best way to parse a URL into its corresponding paths, such that https://www.example.com/path/to/directory/file.jpeg?param1=foo&param2=bar Results in an array holding Array( ["scheme"] => "https", ["host"] => www.example.com ["directory"] => "path/to/directory" ["filename"] => "file" ["extension] => "jpeg" ["path"] => "path/to/directory/file.jpeg", ["file"] => "file.jpeg" ["params"] => Array( ["param1"] => "foo", ["param2"] => "bar" ) ) Note: The keys do not need to be named like

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

試著忘記壹切 提交于 2019-12-02 18:13:31
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 using Python? I can do urlparse but what next? Python has a library for parsing URLs . import urlparse url_data = urlparse.urlparse("http://www.youtube.com/watch?v=z_AbfPXTKms&NR=1") query = urlparse.parse_qs(url_data.query) video = query["v"][0] I've created youtube id parser without regexp: def video_id(value): """ Examples: - http://youtu.be