Skip to content
Advertisement

String after not visible when scraping beautifulsoup

I’m scraping news article. Here is the link. enter image description here

So I want to get that “13” string inside comment__counter total_comment_share class. As you can see that string is visible on inspect element and you can try it yourself from the link above. But when I did find() and print, that string is invisible so I can’t scrape it. This is my code:

JavaScript

From my code I’m using find() on comment__read__text class to make it more clear I can find the elements but that “13” string. The result is same if I’m using find() on comment__counter total_comment_share class. This is the output from code above:

JavaScript

As you can see the “13” string is not there. Anyone knows why? Any help would be appreciated.

Advertisement

Answer

it’s because a request was made while the page was loading which makes the page renders the content dynamically. Try this out:

JavaScript

PS: if you’re interested in scraping all the comments, just change limit to 100000 which will get you all the comments in one request as JSON.

Advertisement