Get Tweet text (xpath query)
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Hi,

I'd like an xpath query that returns the text of a Tweet, given a URL such as this:

https://twitter.com/BarackObama/status/974015556675391488

It should not, however, return the text of any reply tweets.

Also, you should be able to test it here, and your solution should be a link to your solution on oraclize.it:

http://app.oraclize.it/home/test_query

Note that the Oraclize implementation seems different than others. Here's an example to get you started, which should work (and works on other Xpath implementations), but unfortunately on Oraclize it returns the text of the replies as well:

html(https://twitter.com/BarackObama/status/974015556675391488).xpath(//*[contains(@class, 'tweet-text')][1]//text())

(Just paste that into the oraclize website and hit "test query")

Thank you.

awarded to enderdba
Tags
xpath

Crowdsource coding tasks.

1 Solution

Winning solution

The problem is, you were using the wrong class selector, as tweet-text is the general class for all tweets. When you access a permalink using the URL from Twitter, it returns a class that points to the main tweet that the permalink is refering:

html(https://twitter.com/BarackObama/status/974015556675391488).xpath(//div[contains(@class, "permalink-tweet-container")]//p[contains(@class, "tweet-text")]//text())

As the given tweet, it returns:


["Just because I have more time to watch games doesn\u2019t mean my picks will be better, but here are my brackets this year: ", "https://", "go.obama.org/2018bracket", "\u00a0", "pic.twitter.com/gnNXw0Ysxr"]

Try it in Oraclize.it:

http://app.oraclize.it/home/test_query#VVJMKEdFVCk=:aHRtbChodHRwczovL3R3aXR0ZXIuY29tL0JhcmFja09iYW1hL3N0YXR1cy85NzQwMTU1NTY2NzUzOTE0ODgpLnhwYXRoKC8vZGl2W2NvbnRhaW5zKEBjbGFzcywgInBlcm1hbGluay10d2VldC1jb250YWluZXIiKV0vL3BbY29udGFpbnMoQGNsYXNzLCAidHdlZXQtdGV4dCIpXS8vdGV4dCgpKQ==

Hey Enderba, I've posted a follow-up to this question here if you're interested: https://bountify.co/xpath-query-to-get-tweet-text
bevan 2 years ago