Git Product home page Git Product logo

Comments (2)

niklasb avatar niklasb commented on August 17, 2024

Rather than parsing the source HTML, you should parse the current DOM HTML:

doc = sess.document()
lxml_node = doc.xpath(node.path())[0]

This seems a bit complicated for such a simple operation, but I think it's preferrable over a separate attributes() method for several reasons:

  • All the other methods of the Driver and Node classes communicate with the server to get the data from the live DOM
  • To make this work with the live DOM, we would either create a new document object every time (which is time-consuming) or implement smart caching, so that the document is only recreated if the DOM was changed (which would only be fast if the server could notify us about changes, which is not possible)
  • dryscrape's strength is navigation to a final destination even if there are "obstacles", not extracting data from websites (there is Scrapy for that)
  • It's rarely need

I also can't make Node.xpath('@*') behave as you expect without adapting the webkit_server to allow this. In the current implementation, the node representation on the server side is expecting HTML tag nodes, not attributes or even text.

I realize that in the current implementation, it's not a simple task to extend dryscrape, so probably I will add some kind of factory pattern here to allow you to add your own helper methods to Node.

from dryscrape.

pommygranite avatar pommygranite commented on August 17, 2024

Thanks very much for adding the session document method, which allowed me to complete my little project. It was sufficient in my case, because I didn't need to manipulate the live DOM after the attribute names were known. Navigating two trees in parallel could be unpleasant if I needed to navigate across ajax pages based on those unknown attributes.

I appreciate that data extraction is not dryscrape's strength and Scrapy should be used for more complex requirements, however Scrapy's abilities are not useful when it cannot easily navigate past said obstacles!

Though inspection of a node to find its parent, children, attributes and text could be considered very basic tree functionality, it is a shame the implementation is so complex. Thanks for considering it.

I'll close this issue because there is a workaround (though not the ideal solution).

from dryscrape.

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.