본문 바로가기
[ ★ ]Study/Programming

파이썬 웹 크롤링(Web Crawler)

by nroses-taek 2020. 8. 1.

a 태그 안에 href 이미지 긁어오기

BeautifulSoup을 이용한 웹 긁어오기

from urllib.request import *
from bs4 import BeautifulSoup

http = "URL"

html = urlopen(http + "images")
soup = BeautifulSoup(html, "html.parser")

link_temp = ""
image_local_name = ""

for link in soup.findAll('a'):
    if 'href' in link.attrs:
        link_temp = link.attrs['href']
        try:
            image_local_name = link_temp.split('.')[0]
            urlretrieve(http + link_temp, link.get('href'))
        except:
            continue

 

댓글