|
| 1 | +import scrapeninja from "../../scrapeninja.app.mjs"; |
| 2 | +import { axios } from "@pipedream/platform"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "scrapeninja-scraping-with-js-rendering", |
| 6 | + name: "ScrapeNinja Scraping with JS Rendering", |
| 7 | + description: "Uses the ScrapeNinja real Chrome browser engine to scrape pages that require JS rendering. [See the documentation](https://scrapeninja.net/docs/api-reference/scrape-js/)", |
| 8 | + version: "0.0.{{ts}}", |
| 9 | + type: "action", |
| 10 | + props: { |
| 11 | + scrapeninja, |
| 12 | + url: { |
| 13 | + propDefinition: [ |
| 14 | + scrapeninja, |
| 15 | + "url", |
| 16 | + ], |
| 17 | + }, |
| 18 | + waitforselector: { |
| 19 | + propDefinition: [ |
| 20 | + scrapeninja, |
| 21 | + "waitforselector", |
| 22 | + ], |
| 23 | + optional: true, |
| 24 | + }, |
| 25 | + postwaittime: { |
| 26 | + propDefinition: [ |
| 27 | + scrapeninja, |
| 28 | + "postwaittime", |
| 29 | + ], |
| 30 | + optional: true, |
| 31 | + }, |
| 32 | + dumpiframe: { |
| 33 | + propDefinition: [ |
| 34 | + scrapeninja, |
| 35 | + "dumpiframe", |
| 36 | + ], |
| 37 | + optional: true, |
| 38 | + }, |
| 39 | + waitforselectoriframe: { |
| 40 | + propDefinition: [ |
| 41 | + scrapeninja, |
| 42 | + "waitforselectoriframe", |
| 43 | + ], |
| 44 | + optional: true, |
| 45 | + }, |
| 46 | + extractortargetiframe: { |
| 47 | + propDefinition: [ |
| 48 | + scrapeninja, |
| 49 | + "extractortargetiframe", |
| 50 | + ], |
| 51 | + optional: true, |
| 52 | + }, |
| 53 | + headers: { |
| 54 | + propDefinition: [ |
| 55 | + scrapeninja, |
| 56 | + "headers", |
| 57 | + ], |
| 58 | + optional: true, |
| 59 | + }, |
| 60 | + retrynum: { |
| 61 | + propDefinition: [ |
| 62 | + scrapeninja, |
| 63 | + "retrynum", |
| 64 | + ], |
| 65 | + optional: true, |
| 66 | + }, |
| 67 | + geo: { |
| 68 | + propDefinition: [ |
| 69 | + scrapeninja, |
| 70 | + "geo", |
| 71 | + ], |
| 72 | + optional: true, |
| 73 | + }, |
| 74 | + proxy: { |
| 75 | + propDefinition: [ |
| 76 | + scrapeninja, |
| 77 | + "proxy", |
| 78 | + ], |
| 79 | + optional: true, |
| 80 | + }, |
| 81 | + timeout: { |
| 82 | + propDefinition: [ |
| 83 | + scrapeninja, |
| 84 | + "timeout", |
| 85 | + ], |
| 86 | + optional: true, |
| 87 | + }, |
| 88 | + textnotexpected: { |
| 89 | + propDefinition: [ |
| 90 | + scrapeninja, |
| 91 | + "textnotexpected", |
| 92 | + ], |
| 93 | + optional: true, |
| 94 | + }, |
| 95 | + statusnotexpected: { |
| 96 | + propDefinition: [ |
| 97 | + scrapeninja, |
| 98 | + "statusnotexpected", |
| 99 | + ], |
| 100 | + optional: true, |
| 101 | + }, |
| 102 | + blockimages: { |
| 103 | + propDefinition: [ |
| 104 | + scrapeninja, |
| 105 | + "blockimages", |
| 106 | + ], |
| 107 | + optional: true, |
| 108 | + }, |
| 109 | + blockmedia: { |
| 110 | + propDefinition: [ |
| 111 | + scrapeninja, |
| 112 | + "blockmedia", |
| 113 | + ], |
| 114 | + optional: true, |
| 115 | + }, |
| 116 | + screenshot: { |
| 117 | + propDefinition: [ |
| 118 | + scrapeninja, |
| 119 | + "screenshot", |
| 120 | + ], |
| 121 | + optional: true, |
| 122 | + }, |
| 123 | + catchajaxheadersurlmask: { |
| 124 | + propDefinition: [ |
| 125 | + scrapeninja, |
| 126 | + "catchajaxheadersurlmask", |
| 127 | + ], |
| 128 | + optional: true, |
| 129 | + }, |
| 130 | + viewportWidth: { |
| 131 | + propDefinition: [ |
| 132 | + scrapeninja, |
| 133 | + "viewportwitdh", |
| 134 | + ], |
| 135 | + optional: true, |
| 136 | + }, |
| 137 | + viewportHeight: { |
| 138 | + propDefinition: [ |
| 139 | + scrapeninja, |
| 140 | + "viewportheight", |
| 141 | + ], |
| 142 | + optional: true, |
| 143 | + }, |
| 144 | + viewportDeviceScaleFactor: { |
| 145 | + propDefinition: [ |
| 146 | + scrapeninja, |
| 147 | + "viewportdevicescalefactor", |
| 148 | + ], |
| 149 | + optional: true, |
| 150 | + }, |
| 151 | + viewportHasTouch: { |
| 152 | + propDefinition: [ |
| 153 | + scrapeninja, |
| 154 | + "viewporthastouch", |
| 155 | + ], |
| 156 | + optional: true, |
| 157 | + }, |
| 158 | + viewportIsMobile: { |
| 159 | + propDefinition: [ |
| 160 | + scrapeninja, |
| 161 | + "viewportismobile", |
| 162 | + ], |
| 163 | + optional: true, |
| 164 | + }, |
| 165 | + viewportIsLandscape: { |
| 166 | + propDefinition: [ |
| 167 | + scrapeninja, |
| 168 | + "viewportislandscape", |
| 169 | + ], |
| 170 | + optional: true, |
| 171 | + }, |
| 172 | + extractor: { |
| 173 | + propDefinition: [ |
| 174 | + scrapeninja, |
| 175 | + "extractor", |
| 176 | + ], |
| 177 | + optional: true, |
| 178 | + }, |
| 179 | + }, |
| 180 | + async run({ $ }) { |
| 181 | + const viewport = { |
| 182 | + width: this.viewportWidth, |
| 183 | + height: this.viewportHeight, |
| 184 | + deviceScaleFactor: this.viewportDeviceScaleFactor, |
| 185 | + hasTouch: this.viewportHasTouch, |
| 186 | + isMobile: this.viewportIsMobile, |
| 187 | + isLandscape: this.viewportIsLandscape, |
| 188 | + }; |
| 189 | + |
| 190 | + const response = await this.scrapeninja.scrapeJs({ |
| 191 | + url: this.url, |
| 192 | + waitForSelector: this.waitforselector, |
| 193 | + postWaitTime: this.postwaittime, |
| 194 | + dumpIframe: this.dumpiframe, |
| 195 | + waitForSelectorIframe: this.waitforselectoriframe, |
| 196 | + extractorTargetIframe: this.extractortargetiframe, |
| 197 | + headers: this.headers, |
| 198 | + retryNum: this.retrynum, |
| 199 | + geo: this.geo, |
| 200 | + proxy: this.proxy, |
| 201 | + timeout: this.timeout, |
| 202 | + textNotExpected: this.textnotexpected, |
| 203 | + statusNotExpected: this.statusnotexpected, |
| 204 | + blockImages: this.blockimages, |
| 205 | + blockMedia: this.blockmedia, |
| 206 | + screenshot: this.screenshot, |
| 207 | + catchAjaxHeadersUrlMask: this.catchajaxheadersurlmask, |
| 208 | + viewport, |
| 209 | + extractor: this.extractor, |
| 210 | + }); |
| 211 | + |
| 212 | + $.export("$summary", `Successfully scraped ${this.url} with JS rendering`); |
| 213 | + return response; |
| 214 | + }, |
| 215 | +}; |
0 commit comments