stuckselenum
stuckselenum

Reputation: 11

Is there another way to find the Twitter Tweet element?

The classes for identifying peoples tweets on Twitter are now a bunch of random characters with the new Twitter update, when you're not logged into Twitter, the class name is "tweet" and with that I'm able to locate the Tweets with my program. But once you are logged in they are a bunch of random characters like in the example below.

    class="css-1dbjc4n r-1iusvr4 r-46vdb2 r-5f2r5o r-bcqeeo"

The Xpath looks like this:

    //*[@id="react-root"]/div/div/div/main/div/div[2]/div/div/div/div/div[2]/div/section/div/div/div/div[8]/div/div/article/div/div[2]

For 1, it is way too long and doesn't work either.

I'm trying to make a bot that finds peoples tweets and replies to them.

Upvotes: 1

Views: 2849

Answers (2)

Terence Eden
Terence Eden

Reputation: 14304

I'm trying to make a bot that finds peoples tweets and replies to them.

Firstly, please don't! It's against the Twitter terms of service and is usually annoying.

Secondly, if you are going to do this, use the API. You'll get the tweets directly from that and you will be able to reply more easily.

Thirdly, each individual tweet is encased in an <article> element. The text is the only element in a <span>.

Upvotes: 3

Dmitri T
Dmitri T

Reputation: 167992

For me it looks like:

<span class="css-901oao css-16my406 r-1qd0xha r-ad9z0x r-bcqeeo r-qvutc0">Tweet</span>

therefore I would not stick to the class attribute as it tends to be dynamic, instead I would suggest going for Tweet text using XPath locator like:

//span[text()='Tweet']

More information:

Upvotes: 2

Related Questions