0

i am trying to remove a very specific tag and text inside the html file i am scraping. Does anyone have any idea how i can search and remove this specific tag and text all together?

<p class="align-left">&#xA0; Scheduled Arrival Time</p>

EggRollMan
  • 583
  • 1
  • 8
  • 20

1 Answers1

1

You can use regex to replace a specific element with its content. feel free to edit the regex to match your needs. its selecting any p tag with 'align-left' class .

var pattern = /<(p)\s*class\s*=\s*['\"]\s*align-left\s*['\"]\s*[^<]*<\/\1\s*>/g;
var content = "this is<p class=\"align-left\">&#xA0; Scheduled Arrival Time</p> a line !";
content = content.replace(pattern, "");
console.log(content);

if you need to check if a text exists in a specific tag , you can use this :

var pattern = /<(p)\s*class\s*=\s*['\"]\s*align-left\s*['\"]\s*>[^<]*(Arrival Time)[^<]*<\/\1\s*>/g;
var content = "this is<p class=\"align-left\">&#xA0; Scheduled Arrival Time</p> a line !";
var test2 = "im not <p class=\"align-left\">&#xA0; Scheduled</p> a line !";
content = content.replace(pattern, "");
console.log(content);
console.log(test2);
Javad
  • 437
  • 1
  • 5
  • 14