I have been coding a simple python script for obtaining number of views and number of comments of a list of videos. Using csv, I have converted a tab-separated table into a list of lists, and then I tried to obtain both elements. Inspecting number of views, the element is "div", {"class":"watch-view-count"}
. It works as intended
r = requests.get(list_youtube_reading[n][0]) # it retrieves each video URL from a csv
soup = BeautifulSoup(r.text)
for element in soup.findAll("div", {"class":"watch-view-count"}):
patternviews = re.compile('^(.*?) .*')
scissorviews = patternviews.match(element.text.encode("utf-8"))
views = re.sub('\.','', tijeraviews.group(1))
However, element for number of comments is
<h2 class="comment-section-header-renderer" tabindex="0">
<b>Comments</b>
" • 6"
<span class="alternate-content-link"></span>
</h2>
When I tried to obtain it, with
for element in soup.findAll("h2", {"class":"comment-section-header-renderer"}):
comments = element.text.encode("utf-8")
print comments
nothing happens, and actually soup
doesn't contain any <h2 class="comment-section-header-renderer" tabindex="0">
tag
What can I do in order to retrieve number of comments? I tried to use youtube v3 data API, but for no avail
thanks in advance
`. I'm almost sure that it is not possible to scrape comments number from raw html... although I can be wrong. The closest string that I found is `'COMMENTS_TOKEN': "EhYSC3FPVFpLTDZDUFY4wAEAyAEA4AEDGAY%3D",`
– Juan Luis Chulilla Jul 07 '17 at 16:54