有没有办法在浏览器中呈现抓取的数据而不存储在数据库中。
抓取数据的代码。
search = query.lower()
p_search = "-".join(search.split())
url = "xyz"+p_search
myurl = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
uReq = ureq(myurl)
uRead = uReq.read()
uReq.close()
soup = bs(uRead, 'lxml')
device_profile = soup.find('div', {'id': 'device-profile'})
return render(request, 'phone/device_profile.html', {'device': device_profile})在浏览器中呈现数据的代码。
{% if device %}
{% for row in device %}
{{ row }}
{% endfor %}
{% endif %}发布于 2019-04-26 19:08:51
因此,根据您的喜好使用HTML语言填充您的模板('phone/device_profile.html'),并使用模板。例如:
<html>
<head>
<title>Some title</title>
</head>
<body>
<h2 class="h3 blue">About Oppo Find X</h2>
<ul>
{% for row in device %}
<li>{{ row }}</li>
{% endfor %}
</ul>
</body>
</html>更新:
您需要了解device的格式。它看起来像是一个字符串列表。第二个字符串是要粘贴到模板中的HTML字符串。因此,只需将所需的元素传递给模板,而不是for循环:
return render(request, 'phone/device_profile.html', {'device': device_profile[1]})并在模板中直接使用:
<html>
<head>
<title>Some title</title>
</head>
<body>
{{ device }}
</body>
</html>https://stackoverflow.com/questions/55864179
复制相似问题