-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_html_parsing.sh
More file actions
40 lines (32 loc) · 1.35 KB
/
Copy pathsimple_html_parsing.sh
File metadata and controls
40 lines (32 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
# Simple html parsing pipeline
data="raw.txt"
echo "Making process to run with $data file"
touch traversed_html
touch tokenised
# Sanitization pipeline BUG not working
#cat $data | sed 's/ */ /g' | sed '/<script/,/<\/script>/d' |sed '/<style/, /<\/style>/d' | sed 's/<!--,*-->//g' > sanitized_html
echo "[*] made Initial sanitizaiton read sanitized_html"
cat $data | tr -s ' \+' '\n'| sed 's/>\([a-zA-Z]\+\)/>\n\1/g' > traversed_html
echo "[*] Made the traversal of html file stored in traversed_html" && sleep 2s
# BUG Tokenization is not working | DOM Manupulation Data isnt being processed in this logic
extraction_flag=0
while IFS= read -r line;do
# Tag extraction string
tag_pattern='.*<h1>.*'
if [[ $line =~ $tag_pattern ]];then
extraction_flag=1
echo $line >> tokenised
fi
if [[ $extraction_flag == 1 ]];then
# Extraction flag stopping logic
# Extract target tag > remove that content from source file
echo "Got this $line with tag recognition of $target"
tag=$(echo $line | grep '<[a-z]\+>') # tag extracted
echo "Extracted Tag $tag"
target=$(cat traversed_html | sed -n '/<$tag>/,/<\/$tag>/p') #Stores the tag data
sed -i '/$target/d' traversed_html # Deleting extracted tag
# Extracting information for relevent tokenisation
echo $target >> tokenised && echo "Written to the file"
fi
done < traversed_html