gkdnjsdls
2022.03.25
@gkdnjsdls님이 새 포스트를 작성했습니다.
자유로운 크롤링
from selenium import webdriver from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.by import By import time chrome_driver = ChromeDriverManager().install() service = Service(chrome_driver) driver = webdriver.Chrome(service=service) login_url = "https://nid.naver.com/nidlogin.login" driver.get(login_url) time.sleep(2) my_id = "comu" my_pw = "12345" driver.execute_script("document.getElementsByName('id')[0].value = '" + my_id + "'") driver.execute_script("document.getElementsByName('pw')[0].value = '" + my_pw + "'") time.sleep(1) button = driver.find_element(By.ID, "log.login") button.click() time.sleep(1) comu_url = "https://cafe.naver.com/codeuniv" driver.get(comu_url) time.sleep(1) menu = driver.find_element(By.ID, "menuLink90") menu.click() time.sleep(1) driver.switch_to.frame("cafe_main") time.sleep(1) xpath = "/html/body/div[1]/div/div[4]/table/tbody/tr[1]/td[1]/div[3]/div/a" writing = driver.find_element(By.XPATH, xpath) writing.click() time.sleep(1) content = driver.find_element(By.CSS_SELECTOR, "div.se-component-content").text print(content) driver.close()
gkdnjsdls
2022.03.24
@gkdnjsdls님이 새 포스트를 작성했습니다.
한영사전 만들기
from selenium import webdriver from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.by import By import time import csv chrome_driver = ChromeDriverManager().install() service = Service(chrome_driver) driver = webdriver.Chrome(service=service) papago_url = 'https://papago.naver.com/' driver.get(papago_url) time.sleep(3) button = driver.find_element(By.CSS_SELECTOR, "button.btn_switch___x4Tcl") button.click() time.sleep(1) f = open('./my_papago.csv','r', encoding='utf-8-sig') k_word=csv.reader(f) k=[] for i in k_word:     k.append(i[1]) f.close() k=k[1:] form = driver.find_element(By.CSS_SELECTOR, "textarea#txtSource") e=[] for i in k:     form.send_keys(keyword)       button = driver.find_element(By.CSS_SELECTOR, "button#btnTranslate")     button.click()     time.sleep(2)         result = driver.find_element(By.CSS_SELECTOR, "div#txtTarget").text     e.append(result)     form.clear() for i in range(len(k)) :     print(f'{k[i]} :  {e[i]}')
gkdnjsdls
2022.03.21
@gkdnjsdls님이 새 포스트를 작성했습니다.
나만의 번역 사전 만들기
from selenium import webdriver from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.by import By import time chrome_driver = ChromeDriverManager().install() service = Service(chrome_driver) driver = webdriver.Chrome(service=service) URL = "https://papago.naver.com/?sk=en&tk=ko&hn=1" # banana를 포르투갈어로 번역해서 다른 분거 참고, 영어를 한국어로 바꿔주게 설정하고 URL복붙 driver.get(URL) time.sleep(3) dict={} while True:     question = input("번역 할 영단어를 입력(0을 입력하면 종료됩니다) : ")     if question=='0':         driver.close()         break     form = driver.find_element(By.CSS_SELECTOR, "textarea#txtSource")     form.send_keys(question)     button = driver.find_element(By.CSS_SELECTOR, "button#btnTranslate")     button.click()     time.sleep(2)     result = driver.find_element(By.CSS_SELECTOR, "div#txtTarget")     dict[question]=result.text print(dict) driver.close()