강의

멘토링

커뮤니티

Inflearn Community Q&A

ajh74575661's profile image
ajh74575661

asked

[New Revised Edition] This is Real Crawling - Basic Course

Practical Crawling Step 3 : How to Crawl Multiple Pages [URL Manipulator]

vs code 결과출력이 안됩니다

Written on

·

138

0

- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요!
- 먼저 유사한 질문이 있었는지 검색해보세요.
- 서로 예의를 지키며 존중하는 문화를 만들어가요.
- 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요.

 

import requests
from bs4 import BeautifulSoup

for i in range(1,5):
    response = requests.get("https://startcoding.pythonanywhere.com/basic?page={i}")
    html = response.text
    soup = BeautifulSoup(html, 'html.parser')
    items = soup.select(".product")
    for item in items:
        category = item.select_one(".product-category").text
        name = item.select_one(".product-name").text
        link = item.select_one(".product-name > a").attrs['href']
        price = item.select_one(".product-price").text.split('원')[0].replace(',', '')
        print(category, name, link, price)

코드 실행은 잘 되는데 결과값이 밑에 출력이 안되네요. 설정문제 같은데 어떻게 해결해야 하나요

python웹-크롤링

Answer 1

0

startcoding님의 프로필 이미지
startcoding
Instructor

response = requests.get(f"https://startcoding.pythonanywhere.com/basic?page={i}")

오타가 있네요~~ㅎㅎ

f-string 으로 바꾸어 주셔야 합니닷

ajh74575661's profile image
ajh74575661

asked

Ask a question