셀레늄
셀레늄과 bs4를 이용한 도서정보 가져오기
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import requests
url = 'http://www.yes24.com/Main/default.aspx'
driver = webdriver.Chrome()
driver.get(url)
elem = driver.find_element(By.ID, 'query')
elem.send_keys('파이썬')
elem = driver.find_element(By.XPATH, '//*[@id="yesSForm"]/fieldset/span[2]/button')
#elem.send_keys(Keys.ENTER)
elem.click()
# 데이터 가져오기
soup = BeautifulSoup(driver.page_source, 'lxml')
book_list = soup.find('ul', attrs={'id': 'yesSchList'})
books = book_list.find_all('li')
for i, book in enumerate(books) :
title = book.find('a', attrs={'class' : 'gd_name'})
price = book.find('strong', attrs={'class' : 'txt_num'})
rating = book.select('span.rating_grade em')
if not rating : continue
if float(rating[0].get_text()) < 9.6 : continue
print(title.get_text(), price.get_text(), rating[0].get_text())