편집 기록

편집 기록
  • 프로필 편집요청빌런님의 편집
    날짜2020.04.08

    파이썬 크롤링 에러입니다. 'NoneType' object is not subscriptable


    장고 모델을 만들고 view 화면에 아래처럼 코드를 작성했습니다.

    def scrape(request):
        from bs4 import BeautifulSoup
        import requests
    
        if request.method == "POST":
            keyword = request.POST.get("keyword")
            page = request.POST.get("page")
    
            for i in range(1, int(page) + 1):
                req = requests.get(
                    "https://coinpan.com/?error_return_url=%2Ffree&vid=&mid=free&act=IS&is_keyword="
                    + keyword
                    + "&where=document&page="
                    + str(i)
                )
                soup = BeautifulSoup(req.content, "html.parser")
    
                for i in soup.find_all("a", class_="document_link"):
                    keyword = i.text
    
                    link_address = "https://coinpan.com/" + i.find("a")["href"]
    
                    if link_address != "" and keyword is not None:  
                        Keyword.objects.create(
                            word=keyword, link=link_address,
                        ) 
                        data = Keyword.objects.all()
                return render(request, "scrape_result.html", {"data": data})
    
        else:
    
            return render(request, "index.html", {})
    

    실행하면,

    위에 < link_address = "https://coinpan.com/" + i.find("a")["href"] > 이 부분이 아래처럼 에러 나옵니다.

    " TypeError at /
    'NoneType' object is not subscriptable" 
    

    자료를 아무리 찾아봐도 문제를 모르겠어요.

  • 프로필 nowp님의 편집
    날짜2020.04.07

    파이썬 장고에서 크롤링 에러입니다. 'NoneType' object is not subscriptable


    장고 모델을 만들고 view 화면에 아래처럼 코드를 작성했습니다.

    def scrape(request):
        from bs4 import BeautifulSoup
        import requests
    
        if request.method == "POST":
            keyword = request.POST.get("keyword")
            page = request.POST.get("page")
    
            for i in range(1, int(page) + 1):
                req = requests.get(
                    "https://coinpan.com/?error_return_url=%2Ffree&vid=&mid=free&act=IS&is_keyword="
                    + keyword
                    + "&where=document&page="
                    + str(i)
                )
                soup = BeautifulSoup(req.content, "html.parser")
    
                for i in soup.find_all("a", class_="document_link"):
                    keyword = i.text
    
                    link_address = "https://coinpan.com/" + i.find("a")["href"]
    
                    if link_address != "" and keyword is not None:  
                        Keyword.objects.create(
                            word=keyword, link=link_address,
                        ) 
                        data = Keyword.objects.all()
                return render(request, "scrape_result.html", {"data": data})
    
        else:
    
            return render(request, "index.html", {})
    

    실행하면,

    위에 < link_address = "https://coinpan.com/" + i.find("a")["href"] > 이 부분이 아래처럼 에러 나옵니다.

    " TypeError at /
    'NoneType' object is not subscriptable" 
    

    자료를 아무리 찾아봐도 문제를 모르겠어요.

  • 프로필 yubin cho님의 편집
    날짜2020.04.07

    파이썬 장고에서 크롤링 에러입니다.


    장고 모델을 만들고 view 화면에 아래처럼 코드를 작성했습니다.

    def scrape(request): from bs4 import BeautifulSoup import requests

    if request.method == "POST":
        keyword = request.POST.get("keyword")
        page = request.POST.get("page")
    
        for i in range(1, int(page) + 1):
            req = requests.get(
                "https://coinpan.com/?error_return_url=%2Ffree&vid=&mid=free&act=IS&is_keyword="
                + keyword
                + "&where=document&page="
                + str(i)
            )
            soup = BeautifulSoup(req.content, "html.parser")
    
            for i in soup.find_all("a", class_="document_link"):
                keyword = i.text
    
                link_address = "https://coinpan.com/" + i.find("a")["href"]
    
                if link_address != "" and keyword is not None:  
                    Keyword.objects.create(
                        word=keyword, link=link_address,
                    ) 
                    data = Keyword.objects.all()
            return render(request, "scrape_result.html", {"data": data})
    
    else:
    
        return render(request, "index.html", {})
    

    실행하면,

    위에 < link_address = "https://coinpan.com/" + i.find("a")["href"] > 이 부분이 아래처럼 에러 나옵니다.

    " TypeError at / 'NoneType' object is not subscriptable"

    자료를 아무리 찾아봐도 문제를 모르겠어요 ㅠㅠ