Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running jQuery on a static HTML file from Bash

I'm trying to write a simple script to simply check a webpage for a specific value:

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

I'd like to automate this from a Bash script to be run at an interval. I'm also fine with using Python. I need to essentially make an HTTP request, get the response, and have a way to intelligently query the result. Is there a library which will help me with the querying part?

like image 705
Naftuli Kay Avatar asked Feb 29 '12 18:02

Naftuli Kay


People also ask

Can you use jQuery in HTML?

At its core, jQuery is used to connect with HTML elements in the browser via the DOM. The Document Object Model (DOM) is the method by which JavaScript (and jQuery) interact with the HTML in a browser. To view exactly what the DOM is, in your web browser, right click on the current web page select “Inspect”.

Where do I put jQuery in HTML?

Step 1: Open the HTML file in which you want to add your jQuery with the help of CDN. Step 2: Add <script> tag between the head tag and the title tag which will specify the src attribute for adding your jQuery.

Is jQuery static or dynamic?

The reason to work jquery with static content is they are known to DOM, and can handle the events of known elements. but with dynamic contents you have to bind the event with that element by using .

Can you put jQuery in a JavaScript file?

Re: using jQuery in a javascript file It is set up for the CSS and javaScript to be inside the HTML file. And because it uses a CDN version of jQuery, you don't have to load anything on your server!


1 Answers

Xpath is great for querying html.

Something like this:

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

In chrome developer tool you can use the search box in the Elements tab to test the expression.

Quick run in terminal:

$echo '<div id="test" text="foo">Hello</div>' | xpath '//div[@id="test"]/@text' 
Found 1 nodes:
-- NODE --
 text="foo"
like image 183
ebaxt Avatar answered Nov 01 '22 09:11

ebaxt