i want to get 27 as a text from
` transform:rotate(27deg)`
<div class="anlik-ruzgar-ikon"><img class="imgPR" ng-src="../Images_Sys/main_page/ryon-gri.svg" ng-style="{'transform': 'rotate(' sondurum[0].ruzgarYon 'deg)'}" src="../Images_Sys/main_page/ryon-gri.svg" style="transform: rotate(27deg);"> </div>
my current code is soup.find('img', class_= 'imgPR')
and when i run, code shows all the img class
. what add next to get 27.
CodePudding user response:
You can use next example how to locate right tag and parse the number from style=
attribute:
import re
from bs4 import BeautifulSoup
html_doc = """
<div class="anlik-ruzgar-ikon"><img class="imgPR" ng-src="../Images_Sys/main_page/ryon-gri.svg" ng-style="{'transform': 'rotate(' sondurum[0].ruzgarYon 'deg)'}" src="../Images_Sys/main_page/ryon-gri.svg" style="transform: rotate(27deg);"> </div>
"""
soup = BeautifulSoup(html_doc, "html.parser")
# locate right tag:
img = soup.select_one(".imgPR")
# get style property:
style = img["style"]
# parse the number from there:
deg = re.search(r"(\d )deg", style).group(1)
print(deg)
Prints:
27