K
K
Katerina92_lomova2021-09-30 07:54:43
Python
Katerina92_lomova, 2021-09-30 07:54:43

Parsing text in python. How to display only lines that contain a certain word?

I've parsed text from jobs and descriptions, and now I need to output lines that, for example, only contain the word "php".

Is it possible to do this in a Parsing request? Or only date the frame needs to be filtered by a cycle.

Code example:

num_of_page = 20
job_elements = []
for i in range(num_of_page): 
    URL ="https://career.habr.com/vacancies?divisions[]=frontend&page=" + str(i+1)+ "&type=all"    
    page = requests.get(URL)  
    soup = bs(r.text, "html.parser")  
    vacancies_names = soup.find_all('a', class_='vacancy-card__title-link'for name in vacancies_names:
        job_elements.append(name.get_text())

job_elements=pd.DataFrame(job_elements)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
o5a, 2021-09-30
@Katerina92_lomova

Like any test for the occurrence of a substring in a string:
if 'php' in name.get_text():

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question