python - How can I scrape videos from a YouTube search? -
i want search specific keyword , scrape videos urls.
i know code paste not going that, want show have done.
chrome_path = r"c:\users\admin\documents\chromedriver\chromedriver.exe" driver = webdriver.chrome(chrome_path) driver.get("https://www.youtube.com/results?sp=caisaggbubq%253d&q=minecraft") links = driver.find_elements_by_partial_link_text('/watch') link in links: links = (links.get_attribute("href"))
how can scrape links , save them file?
here code gives title , url of video light , easy :)
from bs4 import beautifulsoup import urllib.request def searchvid(search): responce = urllib.request.urlopen('https://www.youtube.com/results?search_query='+search) soup = beautifulsoup(responce) divs = soup.find_all("div", { "class" : "yt-lockup-content"}) in divs: href= i.find('a', href=true) print(href.text, "\nhttps://www.youtube.com"+href['href'], '\n') open(searchstring.replace("%20", "_")+'.txt', 'a') writer: writer.write("https://www.youtube.com"+href['href']+'\n') print("what looking for?") searchstring = input() searchvid(searchstring.replace(" ", "%20"))
Comments
Post a Comment