Dhwani Swadia
Dhwani Swadia

Reputation: 1

How to make importxml only give a certain data

I am trying to get only the number of likes from a website. Currently, I am using

=IMPORTXML("https://www.abillionveg.com/articles/vegan-diet-nutrition-guide","//button")

However, it gives me data from all of the buttons. Can someone help me modify the formula to show only the likes? Sorry if this is a basic question, I am just learning.

Upvotes: 0

Views: 696

Answers (1)

Tanaike
Tanaike

Reputation: 201643

You want to retrieve the number of the number of likes using IMPORTXML.

If my understanding is correct, how about this answer?

Modified formula 1:

=INDEX(SPLIT(IMPORTXML(A1,"//div[@class='ArticleActions__Container-sc-15ye7g8-0 huWdyg'][1]//span[contains(text(),'likes')]")," "),1)
  • The URL of https://www.abillionveg.com/articles/vegan-diet-nutrition-guide is put in the cell "A1".
  • The xpath is //div[@class='ArticleActions__Container-sc-15ye7g8-0 huWdyg'][1]//span[contains(text(),'likes')].
  • Retrieve the value using IMPORTXML.
  • Retrieve the number of ### from the value like ### likes using SPLIT and INDEX.

Result:

enter image description here

Modified formula 2:

=REGEXEXTRACT(IMPORTXML(A1,"//script[@id='__NEXT_DATA__']"),"likesCount""\:(\d+)") - 1
  • This result is the same with Modified formula 1.

Note:

  • For example, if =IMPORTXML(A1,"//div[@class='ArticleActions__Container-sc-15ye7g8-0 huWdyg'][1]//span[contains(text(),'likes')]") is used, 100 likes is retrieved.

References

Upvotes: 1

Related Questions