Home html How to Pass HTML Tags on Python

How to Pass HTML Tags on Python

Author

Date

Category

There is a question of how to parse HTML pages on Python or rather here is a link to the page: https: // 3dtoday.ru/3D-Models?page=1 .
It is necessary to poore this piece of code:

& lt; div class = "threedmodels_models_list__elem__title" & gt;
                & lt; a href = "https://3dtoday.ru/3d-models/for-home/kitchen/derzhatel-filtra-rozhka-kofevarki" title = "" & gt;
                  Coffee makers horn filter holder.
                & lt; / a & gt;
              & lt; / div & gt;

I do not understand how to spar tag text & lt; A & GT; ?


Answer 1

You needed to use Requests and BS4

import requests
From BS4 Import Beautifulsoup
R = Requests.get ('https://3dtoday.ru/3d-models?page=1')
Soup = Beautifulsoup (R.Text, 'HTML.PARSER')
Element = Soup.find_all ('Div', class _ = 'threedmodels_models_list__elem__str')
Elem_Soup = Beautifulsoup (STR (Element [1]), 'HTML.PARSER')
title = elem_soup.find_all ('A') [2] .text
Print (Title)

output:
Coffee maker horn filter holder.

Reply to the comment to get headlines 18 elements, you need to add a cycle

for index in range (18):
  elem_soup = Beautifulsoup (Element [Index]), 'HTML.PARSER')
  title = elem_soup.find_all ('A') [2] .text
  Print (Title)

Answer 2

Popular Library for XML and HTML Parsing.
http://zetcode.com/python/beautifulsoup/

Discern about a similar question.
https://stackoverflow.com/q/13240700/13468321

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions