Live data from Hacker News

Htmlq: like jq, but for html

github.com

111–120 of 172 posts

Re: Htmlq: like jq, but for html

#111
post #44
post #31

This is very nice! For reasoning about tree-based data such as HTML, I also highly recommend the declarative programming language Prolog. HTML documents map naturally to Prolog terms and can be readily reasoned about with built-in language mechanisms. For instance, here is the sample query from the htmlq README, fetching all elements with id get-help from https://www.rust-lang.org , using Scryer Prolog and its SGML a…

It's pretty easy in Python too, eg.: >>> soup = BeautifulSoup(requests.get("https://www.rust-lang.org").text) >>> [x["href"] for x in soup.find_all("a")] ['/', '/tools/install', '/learn', 'https://play.rust-lang.org/', '/tools', '/governance', '/community', 'https://blog.rust-lang.org/',...

In a certain sense (for example, when measuring brevity), it is indeed easy to write this example in Python. However, the Python version also illustrates that many different language constructs are needed to express the intended functionality. In comparison to Prolog, Python is a quite complex language with many different language constructs, including loops, objects, methods, assignment, dictionaries etc. all of which are used in this example.

As I see it, a key attraction of Prolog is its simplicity: With a single language construct (Horn clauses), you are able to express all known computations, and the example queries I posted show that only a single language element, namely again Horn clauses to express a query, is needed to run the code. The Prolog query, and also every Prolog clause, is itself a Prolog term and can be inspected with built-in mechanisms.

As a consequence, an immediate benefit of using Prolog for such use cases is that you can easily reason about user-specified queries in your applications, and for example easily allow only a safe subset of code to be run by users, or execute a user-specified query with different execution strategies etc. In comparison, Python code is much harder to analyze and restrict to a particular subset due to the language's comparatively high syntactic complexity.

Re: Htmlq: like jq, but for html

#113
post #78
post #75

"htmlq: like jq, but for HTML" "jq is like sed for JSON data" sed: "While in some ways similar to an editor which permits scripted edits (_such as ed_), sed works by making only one pass over the input(s)" ed: "ed is a line-oriented text editor". Software definition through a reference to another software is somewhat confusing. Potential users come from different backgrounds (I had no idea what is jq), and it is not…

What's this thing called a "computer" that people keep going on about, anyway?

Sort of related: [Expecting Short Inferential Distances](https://www.readthesequences.com/Expecting-Short-Inferential...)

Re: Htmlq: like jq, but for html

#114

Earlier quoted context omitted.

1st sentence - Explaining the tool for those the tool was made for without beating around the bush. 2nd sentence - Explaining the tool to folks in the general web domain what it can do for them. 3rd sentence - Explaining where to learn how to use the tool if you've stumbled across it but web is not your area of expertise. All that info fits in nearly 25 words then it lists the options for the tool and jumps straight…

I disagree. The 2nd sentence contains, "extract bits content." What is that? If you're going to write a minimal introduction, at least make sure it's not confusing. I get the feeling the author felt compelled to write an introduction and did so with as little effort as possible.

I believe he tailored it to his target audience. If you find it confusing, you are likely not it.

Re: Htmlq: like jq, but for html

#115
post #96

Earlier quoted context omitted.

I just wanted to be slightly more descriptive and less likely to collide with other tools.

Hahah, I love how this is your second comment in 10 years on HN.

Hah. Yeah. I had another account for a little while but then HN started to let me reset the password for this one quite recently, so here I am.

Re: Htmlq: like jq, but for html

#116
post #111
post #44

Earlier quoted context omitted.

It's pretty easy in Python too, eg.: >>> soup = BeautifulSoup(requests.get("https://www.rust-lang.org").text) >>> [x["href"] for x in soup.find_all("a")] ['/', '/tools/install', '/learn', 'https://play.rust-lang.org/', '/tools', '/governance', '/community', 'https://blog.rust-lang.org/',...

In a certain sense (for example, when measuring brevity), it is indeed easy to write this example in Python. However, the Python version also illustrates that many different language constructs are needed to express the intended functionality. In comparison to Prolog, Python is a quite complex language with many different language constructs, including loops, objects, methods, assignment, dictionaries etc. all of whi…

The benefit of Python is that developers already know about these language constructs, and that more developers know Python than Prolog.

Re: Htmlq: like jq, but for html

#118

Very nice tool. I've long spoiled myself with Powershell's: Invoke-WebRequest eg. # what is the latest release of apache-tomcat? $LINKS=$(Invoke-WebRequest -Uri 'https://tomcat.apache.org/download-80.cgi' | Select-Object -ExpandProperty Links) $LATEST=$($Links | Where-Object -Property href -Match '#8.5.[0-9]+').href.substring(1) $FETCH=$($Links | Where-Object -Property href -match "apache-tomcat-${LATEST}.zip$").href

Should it be $LINKS instead of $Links (2x)?

Re: Htmlq: like jq, but for html

#119

Earlier quoted context omitted.

I disagree. The 2nd sentence contains, "extract bits content." What is that? If you're going to write a minimal introduction, at least make sure it's not confusing. I get the feeling the author felt compelled to write an introduction and did so with as little effort as possible.

I believe he tailored it to his target audience. If you find it confusing, you are likely not it.

As web developer for over a decade "bits content" doesn't mean anything to me. But I understand what the tool does from the rest of the description. Try running a google search for "bits content," [0] it's not a commonly used phrase in web development or anything. It's a poor choice of words.

0. https://www.google.com/search?hl=en&q=%22bits%20content%22

Re: Htmlq: like jq, but for html

#120
post #75

"htmlq: like jq, but for HTML" "jq is like sed for JSON data" sed: "While in some ways similar to an editor which permits scripted edits (_such as ed_), sed works by making only one pass over the input(s)" ed: "ed is a line-oriented text editor". Software definition through a reference to another software is somewhat confusing. Potential users come from different backgrounds (I had no idea what is jq), and it is not…

jq isn't line-oriented, it's json-oriented. it's operaring on a stream of jsons from stdin, so its query is applied to each json in sequence.

I would expect that htmlq run the query a single time for a single html; just like jquery $('#something') or document.querySelector('#something')

Post reply on HN