Running jQuery in a static HTML file from Bash

I am trying to write a simple script to just check a webpage for a specific value:

$("a#infgHeader").text() == "Delivered"; 

I would like to automate this with a Bash script to run at intervals. I am also very good at Python. I essentially need to make an HTTP request, get a response, and get a way to intelligently request the result. Is there a library that will help me with the request part?

+6
source share
5 answers

Xpath is great for html request.

Something like that:

 //a[@id='infgHeader']/@text 

In the Chrome Developer Tool, you can use the search box on the Elements tab to check the expression.

Quick start in terminal:

 $echo '<div id="test" text="foo">Hello</div>' | xpath '//div[@id="test"]/@text' Found 1 nodes: -- NODE -- text="foo" 
+8
source

http://pypi.python.org/pypi/spynner/1.10

Spynner will let you select elements from dom using jquery syntax.

Or there are other libraries that let you parse HTML. BeautifulSoup, lxml

+2
source

Alex MacCaw wrote a nice post that does only what you ask using node.js / JavaScript. There are many opportunities that it brings.

http://alexmaccaw.com/posts/node_jquery_xml_parsing

+1
source

I recently did something similar using nodejs + jsdom both documents are well documented with a low input barrier.

0
source

Html parsing is not trivial for shared websites, because html cannot be prefect, and the DOM can be changed by java-script on the fly, so html parsing may not make sense in this case.

The best way is to use a browser and directly access the DOM, for this you can use a mute browser like phontomjs so that you can script and check everything you need to check

0
source

Source: https://habr.com/ru/post/909663/


All Articles