atom086
2022.03.28
@atom086님이 새 포스트를 작성했습니다.
파이썬 15일차 과제
자유과제로 무신사에서 전체 랭킹 1위 상품 이름을 크롤링 해보았습니다. 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://www.musinsa.com/app/' driver.get(URL) time.sleep(1) xpath='/html/body/div[2]/div/div[2]/div/div[1]/div[2]/ul/li[4]/a' rank=driver.find_element(By.XPATH, xpath) rank.click() time.sleep(1) Xpath="/html/body/div[2]/div[3]/form/div[2]/div[2]/div[3]/ul/li[1]/div[3]/div[2]/p[2]/a" writing = driver.find_element(By.XPATH, Xpath) writing.click() time.sleep(1) content = driver.find_element(By.CSS_SELECTOR, "span.product_title").text print("제품 이름:", content)
atom086
2022.03.25
@atom086님이 새 포스트를 작성했습니다.
파이썬 크롤링편 14일차
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[2]/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() 따라가기만 해도 벅찼는데 자유롭게 할 수 있을까요..
atom086
2022.03.24
@atom086님이 새 포스트를 작성했습니다.
파이썬 13일차 과제
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) switch = driver.find_element(By.CSS_SELECTOR, "button.btn_switch___x4Tcl") switch.click() time.sleep(1) f=open('./my_papago.csv', 'r', encoding="utf-8-sig") k_word = csv.reader(f) korean = [] for i in k_word:     korean.append(i[1]) korean = korean[1:] form = driver.find_element(By.CSS_SELECTOR, "textarea#txtSource") english = [] for i in korean:     form.send_keys(i)     button = driver.find_element(By.CSS_SELECTOR, "button#btnTranslate")     button.click()     time.sleep(2)     result = driver.find_element(By.CSS_SELECTOR, "div#txtTarget").text     english.append(result)     form.clear() for i in range(len(korean)):     print(korean[i], ':', english[i])