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)
I wrote it like this, but the error below appears
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
When I added json without adding it, there was an error related to JavaScript, and I took it out because I thought json could not use it, and suddenly,
AttributeError: 'NoneType' object has no attribute 'find_all'
has changed to error... It's all the same, but suddenly a low error appears
>>> r = requests.get(URL)
>>> r
<Response [200]>
>>> type(r)
<class 'requests.models.Response'>
>>> r.content
It comes in the form of #byte, so if you don't want to decode it separately, r.text
{ { "url":"www.naver.com" }
>>> json_result = json.loads(r.text)
>>> type(json_result)
<class 'dict'>
>>> json_result
{'url': 'www.naver.com'}
I think it's better to review how to use the module...
© 2024 OneMinuteCode. All rights reserved.