I'm having an issue extracting some data from a website. I'm in the middle of creating a ChatBot that is knowledgeable about YouTube, so instead of hard coding the most subscribed channel in, I wanted it so the subscriber count constantly updated whenever the method is called. However, this seems to not be working. Originally, the "regexSubscribed" value was pointing to the website that contained PewDiePie's name, but it wasn't working as well as the subscriber count and just returned empty brackets for both.
The name of the channel isn't the problem, it is more of the fact that the subscriber count isn't updating. Anyone know how to resolve this?
def PewDiePie():
htmlfile = urllib.urlopen("http://ift.tt/1rsX7tc")
htmltext = htmlfile.read()
regexSubscribed = "PewDiePie"
patternSubscribed = re.compile(regexSubscribed)
pewDiePie = re.findall(patternSubscribed, htmltext)
regexSubscribers = "<span id=\"afd-header-subs-30d\">(.+?)</span>"
patternSubscribers = re.compile(regexSubscribers)
subscribers = re.findall(patternSubscribers, htmltext)
print ("The most subscribed YouTube channel is %s, with %s subscribers!" % (pewDiePie, subscribers))
Aucun commentaire:
Enregistrer un commentaire