편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2020.12.23

    파이썬 초보 - beautiful soup 에서 IndexError: list index out of range 에러


    웹스크핑 연습 중에 아래 내용을 실행하면 IndexError: list index out of range 로 에러가 나요.
    왜때문이죠

    import requests
    import re
    from bs4 import BeautifulSoup
    
    url = "https://www.coupang.com/np/search?q=%EB%85%B8%ED%8A%B8%EB%B6%81&channel=user&component=&eventCategory=SRP&trcid=&traid=&sorter=scoreDesc&minPrice=&maxPrice=&priceRange=&filterType=&listSize=36&filter=&isPriceRange=false&brand=&offerCondition=&rating=0&page=1&rocketAll=false&searchIndexingToken=1=4&backgroundColor="
    headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"}
    res = requests.get(url, headers=headers)
    res.raise_for_status()
    soup = BeautifulSoup(res.text, "lxml")
    
    items = soup.find_all("li", attrs={"class":re.compile("^search=product")})
    print(items[0].find("div", attrs={"class":"name"}).get_text())
    
  • 프로필 엽토군님의 편집
    날짜2020.12.23

    파이썬 초보 - beautiful soup 에서 index 에러


    웹스크핑 연습 중에 아래 내용을 실행하면 IndexError: list index out of range 로 에러가 나요.
    왜때문이죠

    import requests
    import re
    from bs4 import BeautifulSoup
    
    url = "https://www.coupang.com/np/search?q=%EB%85%B8%ED%8A%B8%EB%B6%81&channel=user&component=&eventCategory=SRP&trcid=&traid=&sorter=scoreDesc&minPrice=&maxPrice=&priceRange=&filterType=&listSize=36&filter=&isPriceRange=false&brand=&offerCondition=&rating=0&page=1&rocketAll=false&searchIndexingToken=1=4&backgroundColor="
    headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"}
    res = requests.get(url, headers=headers)
    res.raise_for_status()
    soup = BeautifulSoup(res.text, "lxml")
    
    items = soup.find_all("li", attrs={"class":re.compile("^search=product")})
    print(items[0].find("div", attrs={"class":"name"}).get_text())
    
  • 프로필 알 수 없는 사용자님의 편집
    날짜2020.12.23

    파이썬 초보 - beautiful soup 에서 index 에러


    웹스크핑 연습 중에 아래 내용을 실행하면 IndexError: list index out of range 로 에러가 나요. 왜때문이죠

    import requests import re from bs4 import BeautifulSoup

    url = "https://www.coupang.com/np/search?q=%EB%85%B8%ED%8A%B8%EB%B6%81&channel=user&component=&eventCategory=SRP&trcid=&traid=&sorter=scoreDesc&minPrice=&maxPrice=&priceRange=&filterType=&listSize=36&filter=&isPriceRange=false&brand=&offerCondition=&rating=0&page=1&rocketAll=false&searchIndexingToken=1=4&backgroundColor=" headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"} res = requests.get(url, headers=headers) res.raise_for_status() soup = BeautifulSoup(res.text, "lxml")

    items = soup.find_all("li", attrs={"class":re.compile("search=product")}) print(items[0].find("div", attrs={"class":"name"}).get_text())