GithubHelp home page GithubHelp logo

twitter_scraper's Introduction

Twitter Scraper

Scraping twitter content from twitter streaming API, in python3.

How it works

Setup

  1. Copy the config.yml.default to config.yml, and fill your twitter application tokens you got from twitter developers.

  2. just type python3 twitter.py, the listener will start to dump corpus in: corpus/<YYYYMMDD_HHMMSS.txt>

Output

I build this corpus for training the neural network model ChatBot, thus the corpus is arranged as consecutive dialog where even sentences are the response of odd sentences, like:

Line number Sentences
1 happy birthday!
2 thank you :)
3 game of throne is the best drama i've seen.
4 I'll say the walking dead is even better.

Where (1,2), (3,4) are two independent dialog pairs.

Content Filters

Twitter streaming API supports some filter, and the most useful ones are:

Location filter

simply place the logitude and altitude in [South,West,North,East] format, for example:

Place filter
San Francisco [-122.75,36.8,-121.75,37.8])
New York City [-74,40,-73,41]
San Francisco or New York City [-122.75,36.8,-121.75,37.8, -74,40,-73,41]

Language filter

there are threads questioning about language filter is not work, actually is does, it just need to accompanied with track filter, like:

This won't work.
stream.filter(languages=["en"])

This works. stream.filter(languages=["en"], track=['machine', 'learning'])

If you want language other than English

Twitter can't tokenize some languages like Japanese or Chinese correctly, your track parameter won't work for these languages. For example, you might setup:

stream.filter(languages=["ja"], track=['バイト'])

While you expect you will get a lot of tweets about バイト, but you simply can't get it, because twitter can't tokenize Japenses and Chinese correctly.

If you just want some corpus, regardless of the topics, here are the work around: use some generic English keywords instead, like:

stream.filter(languages=["zh"], track=['I', 'you', 'http', 'www', '@', '。', ',', '!', '』', ')', '...', '-', '/'])

According to document, you could add up to 400 keywords on this list, even some emoji also works.

twitter_scraper's People

Contributors

marsan-ma avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.