Please consider github.com/gajus/surgeon the next time you are scraping content. The above example could be rewritten as:
importaxiosfrom'axios';importsurgeon,{subroutineAliasPreset}from'surgeon';constx=surgeon({subroutines:{...subroutineAliasPreset}});exportasyncfunctionscrapeRealtor(){consthtml=awaitaxios.get('https://www.realtor.com/news/real-estate-news/');constdata=x(['sm .site-main article',{image:'so img.wp-post-image | ra src',title:'so h2.entry-title | rdtc',excerpt:'so p.hide_xxs | rdtc',link:'so h2.entry-title a | ra href'}],html);console.log(data);}
Apart from being shorter, each selector is also an assertion – this ensures that if the remote document changes, Surgeon will notify of which selectors are returning unexpected results.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Please consider github.com/gajus/surgeon the next time you are scraping content. The above example could be rewritten as:
Apart from being shorter, each selector is also an assertion – this ensures that if the remote document changes, Surgeon will notify of which selectors are returning unexpected results.