Skip to content

Instantly share code, notes, and snippets.

@heffo42
Created July 6, 2019 23:22
Show Gist options
  • Save heffo42/55073d9d49bcbc5332d7653b1d35ceb2 to your computer and use it in GitHub Desktop.
Save heffo42/55073d9d49bcbc5332d7653b1d35ceb2 to your computer and use it in GitHub Desktop.
Launch a Twitter Advanced Search HTTP Request
import requests
INIT_URL = 'https://twitter.com/search?f=tweets&vertical=default&q={q}&l={lang}'
lang = 'en', keywords = "bitcoin%2C%20crypto%2C%20btc", since = "2019-07-05", until = "2019-07-05"
myUa = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36'
HEADER = {'User-Agent': myUa}
query = '{} since:{} until:{}'.format(keywords, since, until)
query = query.replace(' ', '%20').replace('#', '%23').replace(':', '%3A')
url = INIT_URL.format(q=query, lang=lang)
response = requests.get(url, headers=HEADER)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment