1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| import os from selenium import webdriver import time import pytube
browser = webdriver.Chrome('C:/Users/OHG/Downloads/chromedriver_win32/chromedriver') driver = webdriver.Chrome('C:/Users/OHG/Downloads/chromedriver_win32/chromedriver') browser.implicitly_wait(5) url = "https://www.youtube.com/watch?v=C7qr7-NlNw8&index=1&list=PL3Eb1N33oAXijqFKrO83hDEN0HPwaecV3" ser = "http://jtbc.joins.com/search?term="
browser.get(url)
for a in range(1, 100): b = str(a) os.mkdir(b + "번째 기사") os.chdir(b + "번째 기사") print(a, "번째 url open") titles = browser.find_elements_by_css_selector('#container > h1 > yt-formatted-string') f = open("기사 대본.txt", 'w') for title in titles: Z = title.text S = Z[13:] driver.get(ser + S) driver.find_element_by_css_selector('#content > div.wrap_result.clfix > div.wrap_sch_area > div.area_sch_section.last > div > div > ul > li > div > a').click() abc = driver.find_elements_by_css_selector('#articlebody > div:nth-child(1)') for tex in abc: f.write(tex.text) yt = browser.current_url yt = pytube.YouTube(yt) stream = yt.streams.all() stream[15].download(os.getcwd(), "내용") browser.save_screenshot("Website.png") browser.find_element_by_css_selector('#movie_player > div.ytp-chrome-bottom > div.ytp-chrome-controls > div.ytp-left-controls > a.ytp-next-button.ytp-button').click() os.chdir("..") time.sleep(3) browser.quit()
|