bobbybeamer
bobbybeamer

Reputation: 31

Beautiful Soup Youtube subscribers

I'm using Python with Requests and Beautiful Soup to try to return the number of subscribers for certain Youtube channels using the below code:

import requests
from bs4 import BeautifulSoup

request = 
requests.get("https://www.youtube.com/channel/UCFIjVWFZ__KhtTXHDJ7vgng")
content = request.content
soup = BeautifulSoup(content, "html.parser")
element = soup.find("yt-formatted-string", {"id": "subscriber-count", 
"class": "style-scope ytd-c4-tabbed-header-renderer"})
print(element)

I know everything is installed correctly as it is working with scraping information from different sites but when I run this it just says "None". Any help would be much appreciated.

Upvotes: 2

Views: 1588

Answers (1)

AngelOnFira
AngelOnFira

Reputation: 59

If I had to guess, YouTube is detecting that you are a bot. This can be done multiple ways, but an easy way is to see if the headers you are sending seem to be from a browser. If not, it's an easy way them to get rid of a ton of scraping bots. Maybe look into an API? Youtube or a third party may offer one.

If you really need to automate it yourself, I would recommend using Watir. It is a Ruby library that simulated clicks inside of a browser.

Upvotes: 1

Related Questions