inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

묻고 답해요

172만명의 커뮤니티!! 함께 토론해봐요.

쿠팡 이미지 파일 다운받기에서 동일하게 코드 작성 후 요청하였지만 파일 다운로드가 안됩니다.

미해결

실습으로 끝장내는 웹 크롤링과 웹 페이지 자동화 & 실전 활용

쿠팡 상품 썸네일 전체 다운받기 강의에서 동일하게 코드 작성 후 실행하였지만, 다른 크롤링 정보는 정상작동하지만, 파일이 지정된 폴더로 다운이 되지 않습니다. <작성한 코드> import requests from bs4 import BeautifulSoup base_url = "https://www.coupang.com/np/search?component=&q=" keyword = input("검색할 상품을 입력하세요 : ") url = base_url + keyword headers = { "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" } cookie = { "a" : "b" } req = requests.get(url, timeout=5, headers=headers, cookies=cookie) html = req.text soup = BeautifulSoup(html, "html.parser") items = soup.select("[class=search-product]") rank = 1 for item in items: badge_rocket = item.select_one(".badge.rocket") if not badge_rocket: continue name = item.select_one(".name") price = item.select_one(".price-value") thumb = item.select_one(".search-product-wrap-img") link = item.select_one("a")['href'] print(f"{rank}위") print(item["class"]) print(name.text) print(f"{price.text} 원") print(f"https://www.coupang.com{link}") # print(thumb) if thumb.get("data-img-src"): img_url = f"http:{thumb.get('data-img-src')}" else: img_url = f"http:{thumb['src']}" print(img_url) print() img_req = requests.get(img_url) with open(f"07_coupang/{rank}.jpg", "wb") as f: f.write(img_req.content) rank+=1 키워드는 '노트북'이고, 저장하려는 폴더 이름은 07_coupang, 위치는 "C:\project\Webcrawling\07_coupang" 입니다. 어떤 것이 문제일까요?

  • python
  • 웹-크롤링
  • selenium
  • beautifulsoup
  • 쿠팡
  • 상품썸네일다운받기
solim5351 댓글 2 좋아요 0 조회수 888

인기 태그

인프런 TOP Writers

주간 인기글