본문 바로가기
프로그래밍/프로젝트

구글에서 강아지상 이미지 크롤링하기(실패코드..)

by 숙님 2024. 1. 13.
728x90

참고 코드 

# write_data.py 파일을 쓰기 모드로 열어 내용 쓰기

f = open("C:/doit/새파일.txt", 'w')
for i in range(1, 11):
    data = "%d번째 줄입니다.\n" % i
    f.write(data)
f.close()

 

 

beautiful soup

#!/usr/bin/env python3
# Anchor extraction from HTML document
from bs4 import BeautifulSoup
from urllib.request import urlopen
with urlopen('https://en.wikipedia.org/wiki/Main_Page') as response:
    soup = BeautifulSoup(response, 'html.parser')
    for anchor in soup.find_all('a'):
        print(anchor.get('href', '/'))

 

 

최종 작성 코드 

from google_images_download import google_images_download

response = google_images_download.googleimagesdownload()

arguments = {"keywords": "강아지상 연예인", "limit": 50, "print_urls": True, "format": "jpg"}
paths = response.download(arguments)
print(paths)

다운로드 파일이 자동 생성되나 

하지만 구글에서 막혀서 이미지가 생성되지는 않음...! 

 

댓글