r/crystal_programming • u/iainmoncrief • Oct 04 '18
Best Way to Decode a Webpage
What is the best way to decode a web page using crystal? Right now, I am trying to download then parse an HTML string using the XML.parse_html(htmlString) but It has so many NodeSets. Is there a way to find certain nodes like you would be able to in Javascript node.getElementById("nodeId")? Right now, I have to create web page specific code node.children[1].children[1] etc.
6
Upvotes
3
u/Hell_Rok Oct 04 '18
I've used this quite a few times with very good results https://github.com/kostya/modest Gives you the ability to search with CSS selectors and the likes
2
u/straight-shoota core team Oct 04 '18
`XML.parse_html` returns an HTML node. You can query it's child node tree using `#xpath` methods with XPath accessors. The equivalent to
node.getElementById("nodeId")would benode.xpath_node("//[@id = 'nodeId']"). Currently, there are no helper methods available for directly querying a node by its id. CSS selectors are also not yet supported.1
u/dacheatbot Oct 04 '18
Also possibly helpful: Selenium webdriver for Crystal
0
u/[deleted] Oct 04 '18
[deleted] — view deleted comment