-1

I'm working on a private project, and I've a question about Beautiful Soup. I'm using python 3.9.2 and Beautiful Soup 4.9.3. My html code is: style="transform-origin:50% 50%;transform:rotate(382deg) I want to get the part: 382deg. Does anyone now how to do this using Beautiful Soup? Thanks.

w kooij
  • 22
  • 5

1 Answers1

0

To grab the desired value, You can apply regex technique

style = soup.select_one('style:-soup-contains("rotate")').get('style')

v = re.search(r'rotate\((.*)\)',style).group(1)

Example:

from bs4 import BeautifulSoup
import re
style = '''
<td style="transform-origin:50% 50%;transform:rotate(382deg)"> </td>
'''

soup = BeautifulSoup(style,'lxml')

txt = soup.select_one('td')
t=txt.get('style')
v = re.search(r'rotate\((.*)\)',t).group(1)
print(v)

Output:

382deg
Md. Fazlul Hoque
  • 15,806
  • 5
  • 12
  • 32