Apr-25-2021, 05:45 PM
(Apr-25-2021, 04:36 PM)snippsat Wrote:(Apr-25-2021, 01:57 PM)jimsxxl Wrote: There are 2 exactly the same blocks of code on Youtube:Use CCS selector to get exact tag,in browser firstinspect
right clickCopy ➡ Copy ➡ Selector
In BS then you useselect()
orselect_one()
.
view_count = soup.select_one('#metadata-line > span:nth-child(1)') print(view_count.text)
Output:Sett 18k ganger
Wow, thank you snippsat !
Im learning alot, thanks for all the help.
I also used .replace to remove the text "views".
for t, v in zip(title, views): links = t['href'] # Get video URL view = v.text print("Title:", t.text, "| URL: http://www.youtube.com" + links, "| Views:", view.replace("views", ""))