Update HTML Nodes / Attributes
Author: Gerst20051Created Aug 29, 2022Updated Dec 20, 2023
I would like to do something like the following operations on an HTML file. Can you think of a way to do this?
[$]> echo "$(htmlq ".html.head.title = \"React App Title\"" $react_project_dir/index.html)" > $react_project_dir/index.html
[$]> echo "$(htmlq ".html.head.meta[name=description].content = \"React App Description\"" $react_project_dir/index.html)" > $react_project_dir/index.html
Current Options:
- cheerio
- himalaya
- jsdom
- xmltodict
- yq/xq
Similar Discussions:
I was able to do the following withyq/xq but it converts HTML to XML.
[$]> xq -x '.html.head.title = "Updated Title" | (.html.head.meta[] | select(."@name" == "description") | ."@content") |= "Updated Description"' index.html
Source: mgdm/htmlq