Giter VIP home page Giter VIP logo

twitter-timeline-scraper's Introduction

twitter-timeline-scraper

JavaScript scraper for Twitter embedded timelines.

When you copy and paste the code you get from Twitter, you have to replace this:

<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

... with this, in order to have an onTimelineRender event:

<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";js.setAttribute('onload', "twttr.events.bind('rendered',function(e) {Timeline.onLoad(e)});");fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

In order to get the the serialized object, you need to call Timeline.serialize, and pass the iframe created by the embedded timeline as a parameter to that function. If you don't want to deal with that, adding an event to listen for onTimelineRender should work better for you:

document.addEventListener('onTimelineRender', function(e) {
	var data = Timeline.serialize(e.detail.timeline);
	console.log(data);
});

You can see the example.html file to see how it is used.

Example output is in this format:

{
    "id": "439123783694028800",
    "user": {
        "name": "Alex Sexton",
        "username": "SlexAxton",
        "avatar": {
            "x1": "https://pbs.twimg.com/profile_images/378800000335373005/bfe543e85a3f28e646543a14208a865a_normal.jpeg",
            "x2": "https://pbs.twimg.com/profile_images/378800000335373005/bfe543e85a3f28e646543a14208a865a_bigger.jpeg"
        }
    },
    "text": "JavaScript: The Good Farts.\n\n(I've been holding on to this tweet for 22 months)",
    "time": "2014-02-27T19:44:03.000Z",
    "url": "https://twitter.com/SlexAxton/statuses/439123783694028800",
    "stats": {
        "rt": 51,
        "fav": 46
    },
    "retweeted": true,
    "photo": false,
    "playable": false
}

twitter-timeline-scraper's People

Contributors

joom avatar

Stargazers

星星队长 avatar Cody avatar Morgan Huff avatar Monkey Raptor avatar Meligy avatar Zvi avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

nivertech

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.