• 카테고리

    질문 & 답변
  • 세부 분야

    업무 자동화

  • 해결 여부

    미해결

똑같이 따라했는데 쿠팡 크롤링이 되질 않습니다 무엇이 문제일까요ㅜㅜ?

23.07.12 21:51 작성 조회수 562

0

  • 강의 내용 외 개인적인 실습 사이트의 질문은 답변이 제공되지 않습니다.

  • 문제가 생긴 코드, 에러

    import requests
    from bs4 import BeautifulSoup
    import time
    
    bass_url = "https://www.coupang.com/np/search?component=&q="
    
    keyword = input("검색할 상품을 입력하세요 : ")
    
    search_url = bass_url + keyword
    
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
    }
    
    
    cookie = {"a": "b"}
    
    time.sleep(1)
    req = requests.get(search_url, timeout=5, headers=headers, cookies=cookie)
    
    #print(req.status_code)
    
    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.a["href"]
        
        print(f"{rank}위")
        print(name.text)
        print(f"{price.text} 원")
        print(f"https://www.coupang.com/{link}")
        if thumb.get("date-img-src"):
            img_url = f"http:{thumb.get('date-img-src')}"
        else:
            img_url = f"http:{thumb['src']}"
        print(img_url)        
        print()
        
        # img_req = requests.get(img_url)
        
        # with open(f"C:\soncoding\coupang{rank}.jpg", "wb") as f:
        #     f.write(img_req.content)
            
        
        rank += 1
        
        
        

    타임까지 걸어보고 쿠키까지 한번 변경을 해봤는데 계속 뜨질 않습니다. 베이스는 강사님의 코드와 똑같이 적었습니다!

답변 1

답변을 작성해보세요.

0

쿠팡 크롤링을 위한 기본 설정에서 스크롤해서 영상 아래를 봐주세요.
해결 방법이 적혀있습니다.