Как извлечь значение из атрибутов HTML-тегов в Django - PullRequest
0 голосов
/ 30 октября 2019

Я практикую чистку новых приближающихся фильмов imdb, если быть более точным, мне нравится получать имя, источник, название и т. Д. Из списка фильмов, однако, я получаю вот это ..

[,, ...]

Я пытался извлечь значение многими способами, но безуспешно.

m.img.title m ['title'] m.get ('title') и другие похожие

<< my views.py file >>

    def movies(request):
        import requests
        from bs4 import BeautifulSoup
        http = urllib3.PoolManager()
        headers = requests.utils.default_headers()
        headers.update({ 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'})
        url = "https://www.imdb.com/movies-in-theaters/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=2413b25e-e3f6-4229-9efd-599bb9ab1f97&pf_rd_r=TVZT5ZEDG4QTR3X0H40R&pf_rd_s=right-2&pf_rd_t=15061&pf_rd_i=homepage&ref_=hm_otw_sm"
        req = requests.get(url, headers)
        soup = BeautifulSoup(req.content, 'html.parser')
        movies = soup.find_all('img', attrs={"class": "poster shadowed"})
        return render(request, 'movies.html', {'movies': movies})

<< my movie.html >> {% extends' base.html '%}

    {% block content %}

    <table class="table table-hover table-bordered table-striped table-light">
      {% for m in movies %}
      <tbody>
        <tr>
          <th width="10" scope="row">{{ how to extract the src }}</th>
          <th width="10" scope="row">{{ how to extract the alt }}</th>
          <th width="10" scope="row">{{ how to extract the title }}</th>
        </tr>
      </tbody>
      {% endfor %}
    </table>

    <br/>

    {{ movies }}

    {% endblock %}

<< мой вывод с localhost: 8000 / movies / >>

[,, ...]

Я бы хотел извлечь значение для src, alt, название и положить его в каждую клетку

  <tr>
    <th width="10" scope="row">{{ m['src'] }}</th>
    <th width="10" scope="row">{{ m['alt'] }}</th>
    <th width="10" scope="row">{{ m['title'] }}</th>
  </tr>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...