G
G
gytonnt2021-11-04 19:33:19
Django
gytonnt, 2021-11-04 19:33:19

How to add parsed data in Python to an HTML site?

Good evening! I ran into this problem: I need to display the parsed data on the site so that the line from one list and the line from the other are in the same div block. And so on until the list ends. So far, only this way:
61840ad78a3ea111773425.png
Here is the parser code:

import requests
from bs4 import BeautifulSoup
from django.shortcuts import render


def index(request):
    return render(request, 'main/home.html')


response = requests.get('https://zakupki.gov.ru/epz/order/extendedsearch/results.html?morphology=on&search-filter=+%D0%94%D0%B0%D1%82%D0%B5+%D1%80%D0%B0%D0%B7%D0%BC%D0%B5%D1%89%D0%B5%D0%BD%D0%B8%D1%8F&pageNumber=1&sortDirection=false&recordsPerPage=_10&showLotsInfoHidden=false&sortBy=PUBLISH_DATE&fz44=on&fz223=on&af=on&currencyIdGeneral=-1#')
data = BeautifulSoup(response.text, 'html.parser')
quotes = data.find_all(class_='registry-entry__body')
text = data.find_all(class_='registry-entry__body-value')
id = data.find_all(class_='registry-entry__header-mid__number')


def content(request):
    list_1 = []
    list_2 = []

    for quote in text:
        list_1.append(quote.text)
    for i in id:
        list_2.append(i.text)

    list_content = {
        'Text': list_1,
        'ID': list_2
    }

    context = {
        'info': list_content,
    }

    return render(request, 'main/auctions.html', context)

Here is the HTML code:
{% extends 'main/base.html' %}

{% block title %}
Home
{% endblock %}

{% block text %}

        <div class="auctions_data_base">
            <tr>
                
                <tr>
                    <td>{{ info.Text }}</td>
                </tr>
            </tr>

            <tr>
                
                <tr>
                    <td>{{ info.ID }}</td>
                </tr>
            </tr>
        </div>


{% endblock %}

PS I'm new to programming, so do not judge strictly) if there are comments on the code, I will be glad to any criticism. Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2021-11-07
@gytonnt

Firstly, the task must be divided into two components, the first is to obtain the correct data array; the second is to display it correctly.
The first, I believe, can be solved something like this:

def content(con_text, con_id):
    text_ = [quote.text for quote in con_text]
    id_ = [item.text.strip() for item in con_id]
    return zip(text_, id_)


data = content(con_text=text, con_id=id)
for item in data:
    print(item)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question