A
A
armageddon2342021-11-26 18:10:26
Python
armageddon234, 2021-11-26 18:10:26

How to use conditions in Python parsing?

Let's say we have this HTML code:

<td class = "z1">Слово</td>
<td class = "z1">Слово</td>
<td class = "z1">Слово</td>
<td class = "nul">ПУСТО</td>
<td class = "z1">Слово</td>


how can I make my parsing code add everything to the list, these words, and also, if he stumbles upon a class = nul, he also writes it to the list as an empty value

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Shavaleev, 2021-11-27
@armageddon234

import requests
import lxml
from bs4 import BeautifulSoup

resultList = []
web = 'example.com'
response = requests.get(web)
soup = BeautifullSoup(response.text, "lxml")

for td in soup.findAll('td'):
    resultList.append(td.text)

print(resultList)

Searches for all "td" tags on the page, and then extracts the contents of that tag.
Then I think you can do it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question