开发者

A Regex builder for CSS queries

开发者 https://www.devze.com 2022-12-10 06:23 出处:网络
I\'ve 开发者_运维百科got a problem I need solved using Regex expressions; it involves taking a CSS selector and compiling a regex that matches the string representation of the nodes inside an HTML doc

I've 开发者_运维百科got a problem I need solved using Regex expressions; it involves taking a CSS selector and compiling a regex that matches the string representation of the nodes inside an HTML document. The point is to avoid parsing the HTML as XML and then either making Xpath or DOM queries to apply style attributes.

Does anyone know of a project that already implements something like this in any language? The target platform would be .NET 3.5.


Html Agility Pack


Regular expressions seem like an amazingly bad way of matching those nodes. I'm not sure I follow your problem - why not just use something like jquery to pick out those nodes? eg given a css selector 'div>span.red:first-child',

$('div>span.red:first-child')

would return an array of those matching nodes.

EDIT: Oh, wait - are you trying to do this 'offline', as it were - not in a user's browser? Yeah, ignore my advice. (Even so, I'd still suggest that regular expressions aren't going to help you. Why are you against generating an xml-document representation of the page?)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号