Answer the question
In order to leave comments, you need to log in
How to search in python text and get some value from that text?
Input:
file: (
<div class="form-item">
<label for="firstname">Введите фамилию*</label>
<input type="text" name="firstname" id="firstname" required/>
</div>
<div class="form-item">
<label for="lastname">Введите имя*</label>
<input type="text" name="lastname" id="lastname" required />
</div>
<div class="form-item">
<label for="patronymic">Введите Отчество</label>
<input type="text" name="patronymic" id="patronymic"/>
</div>
) 'firstname'
Answer the question
In order to leave comments, you need to log in
Read about Beautiful Soup, maybe you need to dig in this direction or use something similar
Use lxml
>>> import lxml.html as lh
>>>
>>> raw_html = """<div class="form-item">
... <label for="firstname">Введите фамилию*</label>
... <input type="text" name="firstname" id="firstname" required/>
... </div>
... <div class="form-item">
... <label for="lastname">Введите имя*</label>
... <input type="text" name="lastname" id="lastname" required />
... </div>
... <div class="form-item">
... <label for="patronymic">Введите Отчество</label>
... <input type="text" name="patronymic" id="patronymic"/>
... </div>
... """
>>>
>>> html = lh.fromstring(raw_html)
>>> html.xpath('.//label[@for="firstname"]/text()')[0]
'Введите фамилию*'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question