강의

멘토링

커뮤니티

Inflearn Community Q&A

ironpje1374's profile image
ironpje1374

asked

Introduction to Python and Creating Various Automated Applications Using Web Crawling

BeautifulSoup usage and simple web parsing practice (2) - Naver, Inflearn

다시 한번 질문 드립니다!

Written on

·

246

0

다시한번 답변 감사드립니다

알려 주신곳 참고했는데 정확히 이해가 안돼서 코딩을 아래와 같이 해보았습니다 

from urllib.request import urlretrieve

from urllib.request import urlopen

import urllib.parse as par

from bs4 import BeautifulSoup

import os

url = 'https://www.inflearn.com/courses/it-programming?skill=python&order=seq'

res = urlopen(url)

soup = BeautifulSoup(res, 'html.parser')

data = soup.select('div.card.course.course_card_item')

for i, item in enumerate(data, 1):

    k = item.select_one('div.card-image > figure > img')['src']

    k = k.encode('utf-8')

    print(k)

https://cdn.inflearn.com/public/courses/324416/course_cover/eb9ead17-3a5a-4b29-8c57-50377210876e/\xe1\x84\x82\xe1\x85\xa1\xe1\x86\xb7\xe1\x84\x87\xe1\x85\xa1\xe1\x86\xa8\xe1\x84\x89\xe1\x85\xa1_\xe1\x84\x8b\xe1\x85\xb0\xe1\x86\xb8\xe1\x84\x89\xe1\x85\xa1\xe1\x84\x8b\xe1\x85\xb5\xe1\x84\x90\xe1\x85\xb3.png'
b'https://cdn.inflearn.com/public/courses/324238/course_cover/01193765-1b5d-4964-b8b5-dc9444ecc23e/\xe1\x84\x91\xe1\x85\xa1\xe1\x84\x8b\xe1\x85\xb5\xe1\x84\x8a\xe1\x85\xa5\xe1\x86\xab\xe1\x84\x86\xe1\x85\xa5\xe1\x84\x89\xe1\x85\xb5\xe1\x86\xab\xe1\x84\x85\xe1\x85\xa5\xe1\x84\x82\xe1\x85\xb5\xe1\x86\xbc.png'

이미지에 한글이 있는 이미지는 한글이름으로 된 부분이 이렇게 출력이 되더라구요 제가 뭘 잘못한걸까요?

import urllib.parse as par 을
이용하려고 하니

https%3A%2F%2Fcdn.inflearn.com%2Fpublic%2Fcourses%2F324961%2Fcourse_cover%2F14016100-e54a-4f53-a0fa-f82f58758967%2Fkakao-coding-test-2-eng.png
https%3A%2F%2Fcdn.inflearn.com%2Fpublic%2Fcourses%2F324510%2Fcourse_cover%2F91bed9c2-6ea2-48c8-8f2e-fa50cfd7284a%2FI_O_python_2.png
https%3A%2F%2Fcdn.inflearn.com%2Fpublic%2Fcourses%2F324632%2Fcourse_cover%2Fd9a1bfe7-221a-4fb1-a5e0-c4ae5687f761%2FKakaoTalk_20200205_162918232.png

이렇게 http 뒷부분도 변경이 되더라구요
어떻게 해야할까요? 구글링해도 쉽지 않아서 다시 한번 질문좀 드리도록 하겠습니다

답변해주시면 감사하겠습니다
python웹-크롤링

Answer 1

0

niceman님의 프로필 이미지
niceman
Instructor

안녕하세요. 열심히 하시네요.

해당 예제는 저는 아래와 같이 처리 후 수정했습니다.

참고하세요.

https://github.com/eunki7/python_create_app_1/blob/master/section2/2-8-2_new_1.py

ironpje1374's profile image
ironpje1374

asked

Ask a question