1

The question here is not about is this a good idea or not, because there is a real use-case : I'm scraping a specific website from a headless browser for an internal service and I need to extract data from react.

From an active production application, I would like to retrieve props from the root component using only "pure" JavaScript. The only thing I got is a div right now.

The constraints are:

  • It must be done using pure JavaScript (or using standard React lib)
  • I cannot add/setup react-devtools extensions or things like that

So far I could always hack into an event handler that I would trigger to manage to enter into React context but I'm looking for cleaner alternatives, any ideas?

Community
  • 1
  • 1
John Smith
  • 301
  • 2
  • 6
  • 2
    If you explain the real use case, you would get more specific answers. "I wanna do something that I know is not optimal" requires further explanation beyond "believe me, it's a real use case" – Ruan Mendes Feb 02 '16 at 23:01
  • +1. This may be an example of the [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem), and a better answer could be provided with a less abstracted question – Nathan Hagen Feb 03 '16 at 00:33
  • Oh, I'm sorry, just so you know: I'm scraping a specific website from a headless browser and need to extract data from react – John Smith Feb 03 '16 at 07:06
  • Have you tried using [refs](https://facebook.github.io/react/docs/more-about-refs.html)? – Chris Feb 03 '16 at 07:58
  • React is for rendering your code to the browser, if you want to scrape from any websites use some libraries like JSDOM or cheerio. – Vikramaditya Feb 03 '16 at 08:02
  • @Vikramaditya yes I know JSDOM & cheerio but it's not only for scraping, it's for manipulating an existant UI without access to the source code :) – John Smith Feb 03 '16 at 11:05
  • @Chris sadly I don't have access to the source code or anything related to it, thus I can't use refs – John Smith Feb 03 '16 at 11:06
  • Does this answer your question? [React - getting a component from a DOM element for debugging](https://stackoverflow.com/questions/29321742/react-getting-a-component-from-a-dom-element-for-debugging) – ADJenks Jul 14 '23 at 22:52

0 Answers0