Is there any way to render the scrape data in the browser without storing in database.

code for scrape the data.

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})

code to render the data in the browser.

{% if device %}

     {% for row in device %}

      {{ row }}

    {% endfor %}
{% endif %}

1 Answers

0
Yevhen Kuzmovych On

So fill your template ('phone/device_profile.html') with HTML as you prefer and use the templating. For example:

<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>

Update:

You need to understand the format of device. It looks like it is a list of strings. And the second string is the HTML string that you want to paste into template. So instead of for loop just pass needed element to the template:

return render(request, 'phone/device_profile.html', {'device': device_profile[1]})

and use it in the template directly:

<html>
<head>
    <title>Some title</title>
</head>
<body>
    {{ device }}
</body>
</html>