D
D
Dmitri2020-06-24 13:02:20
Python
Dmitri, 2020-06-24 13:02:20

How to get the value from the tag?

<tr class="img weatherIcoS"> <td class="p1"> <div class="weatherIco n000" title="Ясно"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/n000.gif"/></div> </td> <td class="p2 bR"> <div class="weatherIco n000" title="Ясно"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/n000.gif"/></div> </td> <td class="p3"> <div class="weatherIco d300" title="Облачно с прояснениями"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/d300.gif"/></div> </td> <td class="p4 bR"> <div class="weatherIco d300" title="Облачно с прояснениями"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/d300.gif"/></div> </td> <td class="p5 cur"> <div class="weatherIco d300" title="Облачно с прояснениями"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/d300.gif"/></div> </td> <td class="p6 bR"> <div class="weatherIco d320" title="Облачно с прояснениями, дождь"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/d320.gif"/></div> </td> <td class="p7"> <div class="weatherIco d320" title="Облачно с прояснениями, дождь"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/d320.gif"/></div> </td> <td class="p8"> <div class="weatherIco n300" title="Облачно с прояснениями"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/n300.gif"/></div> </td> </tr>


You need to get the title value, you can't use a slicer

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-06-24
@dmitriy337

Regular Expressions

import re
str = '<tr class="img weatherIcoS"> <td class="p1"> <div class="weatherIco n000" title="Ясно"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/n000.gif"/></div> </td> <td class="p2 bR"> <div class="weatherIco n000" title="Ясно"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/n000.gif"/></div> </td> <td class="p3"> <div class="weatherIco d300" title="Облачно с прояснениями"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/d300.gif"/></div> </td> <td class="p4 bR"> <div class="weatherIco d300" title="Облачно с прояснениями"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/d300.gif"/></div> </td> <td class="p5 cur"> <div class="weatherIco d300" title="Облачно с прояснениями"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/d300.gif"/></div> </td> <td class="p6 bR"> <div class="weatherIco d320" title="Облачно с прояснениями, дождь"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/d320.gif"/></div> </td> <td class="p7"> <div class="weatherIco d320" title="Облачно с прояснениями, дождь"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/d320.gif"/></div> </td> <td class="p8"> <div class="weatherIco n300" title="Облачно с прояснениями"><img alt="" class="weatherImg" src="//sinst.fwdcdn.com/img/weatherImg/s/n300.gif"/></div> </td> </tr>'
titles = re.findall(r'title="([^"]*)"', str)
print(titles) // ['Ясно', 'Ясно', 'Облачно с прояснениями', 'Облачно с прояснениями', 'Облачно с прояснениями', 'Облачно с прояснениями
, дождь', 'Облачно с прояснениями, дождь', 'Облачно с прояснениями']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question