[英]Beautifulsoup css data extraction
I am attempting to extract css data from an html document. 我正在尝试从html文档中提取css数据。 the data points are a variable number of circle xy coordinates generated by the user onto an image and exported into the html as follows:
数据点是用户在图像上生成的可变数量的圆形xy坐标,并按如下方式导出到html中:
#shapes a#rage_circle1{
top: 248px;
left: 231px;
width: 18px;
height: 18px;
border: 1px solid #000000;
background-image: none;
}
I would like an output of the top and left pixel numbers. 我想要顶部和左侧像素数字的输出。
UPDATED: 更新:
this is what I have done so far 这是我到目前为止所做的
from bs4 import BeautifulSoup
import re
soup = BeautifulSoup (open ('index.html'))
x= soup.findAll(text=re.compile('left'))
print (x)
The output generated is all the data between the braces above and is not selecting the "left" string only. 生成的输出是上面花括号之间的所有数据,而不仅仅是选择“左”字符串。 I am not sure why my script is not selecting a particular data between the braces.
我不确定为什么我的脚本没有在花括号之间选择特定的数据。 Any suggestions?
有什么建议么?
I think cssutils is the right choice for your problem. 我认为cssutils是解决您问题的正确选择。 The following snippet will simply output the values of all
top
and left
attributes. 以下代码段将仅输出所有
top
和left
属性的值。
import cssutils
css = cssutils.parseFile('index.html')
for rule in css.cssRules:
print(rule.style.top)
print(rule.style.left)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.