So I'm using Mechanize in Ruby to do some website scraping and want to find all nodes with a specific style
attribute.
I want to return all nodes with a style attribute that has specific top
value on the webpage.
The HTML will look like this:
<div id="c11285" style="position:absolute;top:1px;left:333px;width:65px;height:226px;overflow:hidden;background-color:transparent;z-index:10;border: 1px solid #000" onclick="">
In this case I cannot use the id, because each variation of the page has different ids so I want to search by the top
value in the style
attribute which in this case is 1px
.
I've tried using webPage.search("div['style=top: 1px;']")
However, this does not work as px
seems to cause an error.
Any suggestions on how I could achieve this or is this even possible?
它扫描所有元素并返回style属性中具有top:1px的元素。
//*[contains(@style, 'top:1px')]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.