urltitle
urltitle uses Python 3.7 to return the page title or header-based description for a given URL. Its intended primary use is the inclusion of the returned value in conversations. As a disclaimer, note that the returned title is not guaranteed to be accurate due to many possible factors.
Features
- An in-memory cache is used with a default entry expiration of a week. The cache size and time are customizable.
- Approximately only the fraction of a HTML page required to return a title is read, up to a customizable maximum of 1 MiB.
- A fallback to the
og:titleandtwitter:titleif thetitletag is unavailable. - A PDF title metadata extractor is used for PDF files of up to a customizable maximum size of 8 MiB.
- Up to three attempts are made for resiliency except if there is an unrecoverable error, i.e. 400, 401, 404, etc.
- A guess of
httpsand otherwisehttpis made for a URL with a missing scheme, e.g. git-scm.com/downloads. - SSL verification for https sites can optionally be disabled.
- A fallback to Google web cache is used if a HTML page presents a Distil captcha. It is also used for a PDF which is too large or doesn't have title metadata.
- Diagnostic logging can be optionally enabled for the logger named
urltitleat the desired level. - Some site-specific customizations are configurable:
- Regular expression based URL and title substitutions
- Use of Google web cache
- User-Agent
- Additional headers
- CSS title selector
- Use of
og:titleortwitter:titleovertitletag - Initial read size
Links
Usage
Installation
Python ≥3.7 is required due to a reference
to SSLCertVerificationError.
To install the package, run:
pip install urltitle
Examples
from urltitle import URLTitleReader
reader = URLTitleReader(verify_ssl=True)
# Titles for HTML content
reader.title('https://www.cnn.com/2019/02/11/health/insect-decline-study-intl/index.html')
"Insect numbers in precipitous decline could have 'catastrophic' consequences, warns study - CNN"
reader.title('https://www.youtube.com/watch?v=53YvP6gdD7U')
'Deep Learning State of the Art (2019) - MIT - YouTube'
# Titles for URLs with a missing scheme
reader.title('www.reuters.com/article/us-usa-military-army/army-calls-base-housing-hazards-unconscionable-details-steps-to-protect-families-idUSKCN1Q4275')
"Army calls base housing hazards 'unconscionable,' details steps to protect families | Reuters"
reader.title('reddit.com/r/FoodNerds/comments/arb6qj')
'Paternal high-fat diet transgenerationally impacts hepatic immunometabolism. - PubMed - NCBI : FoodNerds'
reader.title('neverssl.com')
'NeverSSL - helping you get online'
# Titles for non-ASCII URLs
reader.title('https://en.wikipedia.org/wiki/Amanattō')
'Amanattō - Wikipedia'
reader.title('https://fr.wikipedia.org/wiki/Wikipédia:Accueil_principal')
"Wikipédia, l'encyclopédie libre"
# Titles for PDFs having title metadata
reader.title('https://www.diabetes.org.br/publico/images/pdf/artificial-sweeteners-induce-glucose-intolerance-by-altering-the-gut-microbiota.pdf')
'Artificial sweeteners induce glucose intolerance by altering the gut microbiota'
reader.title('https://www.omicsonline.org/open-access/detection-of-glyphosate-in-malformed-piglets-2161-0525.1000230.pdf')
'Detection of Glyphosate in Malformed Piglets'
# Titles for other content showing Content-Type and Content-Length as available:
reader.title('https://www.sciencedaily.com/images/2019/02/190213142720_1_540x360.jpg')
'(image/jpeg) (54K)'
reader.title('https://kdnuggets.com/rss')
'(application/rss+xml; charset=UTF-8)'
reader.title('https://download.fedoraproject.org/pub/fedora/linux/releases/29/Workstation/x86_64/iso/Fedora-Workstation-Live-x86_64-29-1.2.iso')
'(application/octet-stream) (2G)'
# Titles for substituted URLs as per configuration:
reader.title('https://arxiv.org/pdf/1902.04704.pdf')
'[1902.04704] Neural network models and deep learning - a primer for biologists'
reader.title('https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2495396/pdf/postmedj00315-0056.pdf')
"Features of a successful therapeutic fast of 382 days' duration"
reader.title('https://pdfs.semanticscholar.org/1d76/d4561b594b5c5b5250edb43122d85db07262.pdf')
'Nutrition and health. The issue is not food, nor nutrients, so much as processing. - Semantic Scholar'
Exceptions
An error is expected to raise the urltitle.URLTitleError exception.
Customizations
For any site-specific customizations, update (but ideally not replace)
urltitle.config.NETLOC_OVERRIDES with the relevant sites using the preexisting entries in it as examples.
Refer to overrides.py.
The site of a URL is as defined and returned by the URLTitleReader().netloc(url) method in
urltitle.py.
The following examples show various URLs and their corresponding sites for the purpose of entering site-specific customizations:
| URL | Site |
|---|---|
https://www.google.com/search?q=asdf |
google.com |
https://google.com/search?q=hjkl |
google.com |
google.com/search?q=qwer |
google.com |
google.com |
google.com |
GOOGLE.COM |
google.com |
gOogLE.com |
google.com |
https://drive.google.com/drive/my-drive |
drive.google.com |
https://help.github.com/en/ |
help.github.com |
https://github.com/pytorch/pytorch |
github.com |
https://www.amazon.com/gp/product/B01F8POA7U |
amazon.com |
https://rise.cs.berkeley.edu/blog/ |
rise.cs.berkeley.edu |
https://www.swansonvitamins.com/web-specials |
swansonvitamins.com |
Metadata
Release files for urltitle 0.3.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| urltitle-0.3.8.tar.gz | 37.3 kB | Without provenance | Details for urltitle-0.3.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| urltitle-0.3.8-py3-none-any.whl | Python 3 | none | any | Details for urltitle-0.3.8-py3-none-any.whl |
Total release size: 74.5 kB
Release files / urltitle-0.3.8.tar.gz
| Download URL | urltitle-0.3.8.tar.gz |
|---|---|
| Size | 37.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
568735a9bbda0f4fc706333e009156634156d6ec0e3c5847edb4a19f973d967d
|
|
BLAKE2b-256 checksum How to use checksums |
9d7a945fc47db0920f90c09e17df435d87a4d6d20afedbdd97768a5caf347a0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
|
Release files / urltitle-0.3.8-py3-none-any.whl
| Download URL | urltitle-0.3.8-py3-none-any.whl |
|---|---|
| Size | 37.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e75c696386b916b820092914979b3f97ad57d0dcc4e70693a256fae53f5b4b73
|
|
BLAKE2b-256 checksum How to use checksums |
c4d4d055927441aeb3855e705d396a8c4f20322c29fefcb405da6abe757d4e0f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
|
Security for urltitle 0.3.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.