Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.Document;
- import org.jsoup.nodes.Element;
- import org.jsoup.select.Elements;
- public class AdBlocker {
- public static void main(String[] args) {
- // Replace the "html" variable with the actual HTML content
- String html = "<html><body><div class='ad'>Ad 1</div><p>This is some content.</p><div id='ad2'>Ad 2</div></body></html>";
- // Load the HTML document
- Document document = Jsoup.parse(html);
- // Select all elements with class names or attributes commonly used in ad tags
- Elements adElements = document.select(".ad, [class*=ad], [id*=ad], [id*=Ad], [id*=AD], [class*=ad], [class*=Ad], [class*=AD]");
- // Loop through the ad elements and remove them
- for (Element adElement : adElements) {
- adElement.remove();
- }
- // Print the modified HTML document
- System.out.println(document.html());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement