I am currently working in a web scrapping project with ruby on rails and below is the web-page link I am working on.
I have fetched all the (.story p ) from this page and particularly want to remove the last tag having background-color:rgb(255,255,0) Here's the thing I want to remove
I want to select the tag using the custom styling it has. picture for clarity
I have tried everything and not able to do so. I there any other way I can select the desired text and remove it from the doc.
CodePudding user response:
This looks like it works... give it a try
url = "https://www.livelaw.in/top-stories/supreme-court-civil-suit-maintainable-jurisdiction-scope-sau-rajani-vs-sau-smita-2022-liv"
elaw-sc-702-207475?infinitescroll=1")
file = Nokogiri::HTML.parse(URI.open(url))
element = file.xpath("//b[contains(@style,'background-color: rgb(255, 255, 0)')]")
CodePudding user response:
It is usual attribute and you can get element by such selector
element = doc.at("b[style='background-color:rgb(255,255,0)']")
And to remove it
element.remove