Python Extract And Link Hashtag
December 19, 2017Using twitter-text-py
twitter-text-py is a port of twitter-text-rb, where the last release is 2014-01-16.
Note: twitter-text only officially support Java, Ruby, JavaScript and Objective-C. I didn’t find a more recent implementation of twitter-text
for Python.
Install.
pip install twitter-text-py
Code.
import logging
from twitter_text import Autolink
str = u'I am #hello #My World #我爱你'
html = Autolink(str).auto_link_hashtags({'hashtag_url_base': '/t/', 'hashtag_class': 'hashtag'})
logging.info(html)
Output.
I am <a class="hashtag" href="/t/hello" title="#hello">#hello</a> <a class="hashtag" href="/t/My" title="#My">#My</a> World <a class="hashtag" href="/t/我爱你" title="#我爱你">#我爱你</a>
- algo-trading
- algolia
- analytics
- android
- android-ktx
- android-permission
- android-studio
- apps-script
- bash
- binance
- bootstrap
- bootstrapvue
- chartjs
- chrome
- cloud-functions
- coding-interview
- contentresolver
- coroutines
- crashlytics
- crypto
- css
- dagger2
- datastore
- datetime
- docker
- eslint
- firebase
- firebase-auth
- firebase-hosting
- firestore
- firestore-security-rules
- flask
- fontawesome
- fresco
- git
- github
- glide
- godot
- google-app-engine
- google-cloud-storage
- google-colab
- google-drive
- google-maps
- google-places
- google-play
- google-sheets
- gradle
- html
- hugo
- inkscape
- java
- java-time
- javascript
- jetpack-compose
- jetson-nano
- kotlin
- kotlin-serialization
- layout
- lets-encrypt
- lifecycle
- linux
- logging
- lubuntu
- markdown
- mate
- material-design
- matplotlib
- md5
- mongodb
- moshi
- mplfinance
- mysql
- navigation
- nginx
- nodejs
- npm
- nuxtjs
- nvm
- pandas
- payment
- pip
- pwa
- pyenv
- python
- recylerview
- regex
- room
- rxjava
- scoped-storage
- selenium
- social-media
- ssh
- ssl
- static-site-generator
- static-website-hosting
- sublime-text
- ubuntu
- unit-test
- uwsgi
- viewmodel
- viewpager2
- virtualbox
- vue-chartjs
- vue-cli
- vue-router
- vuejs
- vuelidate
- vuepress
- web-development
- web-hosting
- webpack
- windows
- workmanager
- wsl
- yarn