Code Monkey home page Code Monkey logo

Comments (2)

ruippeixotog avatar ruippeixotog commented on May 27, 2024

Hi @emrekanca! Sorry for the long delay. Currently scala-scraper only scrapes web pages to an immutable model - there are no methods to modify the elements, only to retrieve them. For now you should use jsoup directly or use scala-scraper, convert it to HTML with .outerHtml and parse it using jsoup in order to modify it.

from scala-scraper.

ruippeixotog avatar ruippeixotog commented on May 27, 2024

Hi again @emrekanca. Through the new typed element API introduced in version 2.0.0-RC2, it is now possible to remove elements by accessing the underlying HTML library:

scala> val browser = JsoupBrowser.typed()
browser: net.ruippeixotog.scalascraper.browser.JsoupBrowser = net.ruippeixotog.scalascraper.browser.JsoupBrowser@3868bd2b

scala> val doc = browser.parseString("""<div><p>abc</p><span>def</span>""")
doc: net.ruippeixotog.scalascraper.browser.JsoupBrowser.JsoupDocument =
JsoupDocument(<html>
 <head></head>
 <body>
  <div>
   <p>abc</p>
   <span>def</span>
  </div>
 </body>
</html>)

scala> val elem = doc >> pElement("div")
elem: net.ruippeixotog.scalascraper.browser.JsoupBrowser.JsoupElement =
JsoupElement(<div>
 <p>abc</p>
 <span>def</span>
</div>)

// This is browser specific. There will be an equivalent operation in HtmlUnit
scala> elem.underlying.children.select("span").remove()
res1: org.jsoup.select.Elements = <span>def</span>

scala> doc
res2: net.ruippeixotog.scalascraper.browser.JsoupBrowser.JsoupDocument =
JsoupDocument(<html>
 <head></head>
 <body>
  <div>
   <p>abc</p>
  </div>
 </body>
</html>)

from scala-scraper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.