Created
March 8, 2023 07:29
-
-
Save youtube-jocoding/84c78a58b59a780fbf334f4b0977456e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.common.by import By | |
import time | |
import urllib.request | |
options = webdriver.ChromeOptions() | |
options.add_experimental_option("excludeSwitches", ["enable-logging"]) | |
driver = webdriver.Chrome("C:/kefico/chromedriver.exe", options=options) | |
url = "https://pixabay.com/ko/images/search/" | |
keyword = input("검색어를 입력해주세요: ") | |
driver.get(url+keyword) | |
time.sleep(2) | |
imgTags = driver.find_elements(By.CSS_SELECTOR, ".photo-result-image") | |
imgTags = imgTags[0:10] | |
srcList = [] | |
for tag in imgTags: | |
src = tag.get_attribute("src") | |
srcList.append(src) | |
opener = urllib.request.build_opener() | |
opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36')] | |
urllib.request.install_opener(opener) | |
urllib.request.urlretrieve(srcList[0], "test.jpg") |
Author
youtube-jocoding
commented
Mar 8, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment