JSONDecodeError: Expecting value: line 1 column 1 (char 0) 에대해 질문드립니다
조회수 3402회
import requests
import re
import json
req = requests.get(page_urls[0]).json()
html = req.content
soup = BeautifulSoup(html, "lxml")
contents_table = soup.find(name="article")
title = contents_table.find_all("h3 > span")[0]
content_paragraphs = contents_table.find_all(name="div", attrs={"class":"writing_view_box"})
print(title.text)
print("\n")
print(content_paragraphs.text)
이렇게 작성하였는데 아래의 오류가 뜹니다
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
추가적으로 json을 안붙이고 첨했을때 자바스크립트 관련 오류가 떴었고 json쓸수없는 건가 해서 뺐더니 갑자기
AttributeError: 'NoneType' object has no attribute 'find_all'
오류로 변해있네요... 전부 그대로인데 갑자기 저오류가 뜹니다
-
(•́ ✖ •̀)
알 수 없는 사용자 - 〉
1 답변
-
>>> r = requests.get(URL) >>> r <Response [200]> >>> type(r) <class 'requests.models.Response'> >>> r.content #byte 형태로 들어오므로 별도 디코드할거아니면 r.text { "url":"www.naver.com" } >>> json_result = json.loads(r.text) >>> type(json_result) <class 'dict'> >>> json_result {'url': 'www.naver.com'}
모듈 사용법에 대해서 다시 살펴보시는게 좋을거 같아요...
댓글 입력