Comments (2)
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
andNode
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.
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)
- EndOfStreamError when visiting sites (Yelp, google business) remotely HOT 5
- HI contributor question about cookies HOT 1
- Brilliant HOT 1
- Provide instructions for Red Hat / Fedora / CentOS HOT 3
- [request] Session Closed
- dryscrape console.log HOT 3
- Windows 10 Support HOT 1
- Interacting with iframes HOT 2
- Wait javascript page to execute commands HOT 1
- Cannot install HOT 6
- Webkit_server error HOT 6
- {"class":"NodeNotAttachedError","message":"Element at 2 no longer present in the DOM"}
- follow redirects?
- How to make POST request? HOT 2
- image not found error for qt 5.5
- Cannot render page on RedHat, characters all become squares
- Can't get DOM that's generated by javascript HOT 5
- Unable to find QtWebKit on MacOS Darwin HOT 1
- Is it possible to use dryscrape with socks proxy?
- how to override default timeout parameters HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dryscrape.