Creating an alias for xpath expression in xidel with regex and bash

Creating an alias for xpath expression in xidel with regex and bash

If you have already used Xidel, you will often need to locate nodes that have a certain class. To do this more easy, I want to create&nbsp;<code>has-class("class")</code>&nbsp;function that serves as an alias for the expression:

If you have already used Xidel, you will often need to locate nodes that have a certain class. To do this more easy, I want to create has-class("class") function that serves as an alias for the expression:

contains(concat(" ", normalize-space(@class), " "), " class ").

Example:

$ e-xidel.sh example.com '//article/p//img[has-class("wp-image")]'

e-xidel.sh contains this code:

#!/bin/bash

echo -e "$(tput setaf 2) Checking... $(tput sgr0)"

path=$1 expression=$2

expression = '//article/p//img[has-class("wp-image")]'

Regex to replace every * has-class("class") * by * contains(concat(" ", normalize-space(@class), " "), " class ") *

...

...

expression = '//article/p//img[contains(concat(" ", normalize-space(@class), " "), " wp-image ")]'

xoutput=$(xidel $path --printed-node-format=html --output-declaration= -e "$expression")

echo -e "$(tput setaf 1) $xoutput $(tput sgr0)"


regex bash macos

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Bash Select (Make Menus) and Bash select Example

In this tutorial, we will cover the basics of the select construct in Bash. The select construct generates a menu from a list of items. It has almost the same syntax as for loop.If the user enters a number that corresponds to the number of one of the displayed items, then the value of [ITEM] is set to that item. The value of the selected item is stored in the variable REPLY. Otherwise, if the user input is empty, the prompt and the menu list are displayed again.

Bash until Loop and Bash until Loop Example

This tutorial explains the basics of the until loop in Bash. The until loop is used to execute a given set of commands as long as the given condition evaluates to false.

Bash For Loop,The Standard Bash for Loop

In this tutorial, we will cover the basics of for loops in Bash. We will also show you how to use the break and continue statements to alter the flow of a loop.

Bash Functions,Defining Bash Functions

A Bash function is essentially a set of commands that can be called numerous times. The purpose of a function is to help you make your bash scripts more readable and to avoid writing the same repeatedly.

Bash break and continue

Loops allow you to run one or more commands multiple times until a certain condition is met. In Bash, break and continue statements allows you to control the loop execution.