I have a string containing a link. The link often has the form:
http://www.address.com/something#something
Is there a function in python that can remove "#something" from a link?
The fragment identifier introduced by a hash mark # is the optional last part of a URL for a document. It is typically used to identify a portion of that document. The generic syntax is specified in RFC 3986. The hash-mark separator in URIs is not part of the fragment identifier.
var hash = url. substring(url. indexOf('#') + 1); alert(hash); Example 2: This example uses substring() method to display the fragment identifier.
Note that multiple text fragments can appear in one URL. The particular text fragments need to be separated by an ampersand character & .
To request removal of a directory or site, click on the site in question, then go to Site configuration > Crawler access > Remove URL. If you enter the root of your site as the URL you want to remove, you'll be asked to confirm that you want to remove the entire site.
In python 3, the urldefrag
function is now part of urllib.parse
:
from urllib.parse import urldefrag
unfragmented = urldefrag("http://www.address.com/something#something")
('http://www.address.com/something', 'something')
For Python 2 use urlparse.urldefrag:
>>> urlparse.urldefrag("http://www.address.com/something#something")
('http://www.address.com/something', 'something')
Just use split()
>>> foo = "http://www.address.com/something#something"
>>> foo = foo.split('#')[0]
>>> foo
'http://www.address.com/something'
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With