Issue
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.
Solution
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
Answered By - Fazlul
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.