198-web-scraper-link-preview icon indicating copy to clipboard operation
198-web-scraper-link-preview copied to clipboard

got issue

Open Anderies opened this issue 5 years ago • 4 comments
trafficstars

got this error after doing post method at postman with object body "text": "https://fireship.io and https://www.instagram.com"

functions: Beginning execution of "scraper"

(node:3216) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token o in JSON at position 1 at JSON.parse () at cors (D:\ANDERIES\LEARN\ws-fireship\functions\index.js:45:27) at cors (D:\ANDERIES\LEARN\ws-fireship\functions\node_modules\cors\lib\index.js:188:7) at D:\ANDERIES\LEARN\ws-fireship\functions\node_modules\cors\lib\index.js:224:17 at originCallback (D:\ANDERIES\LEARN\ws-fireship\functions\node_modules\cors\lib\index.js:214:15) at D:\ANDERIES\LEARN\ws-fireship\functions\node_modules\cors\lib\index.js:219:13 at optionsCallback (D:\ANDERIES\LEARN\ws-fireship\functions\node_modules\cors\lib\index.js:199:9) at corsMiddleware (D:\ANDERIES\LEARN\ws-fireship\functions\node_modules\cors\lib\index.js:204:7) at exports.scraper.functions.https.onRequest (D:\ANDERIES\LEARN\ws-fireship\functions\index.js:42:5) at runFunction (C:\Users\ASUS\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:622:20) (node:3216) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:3216) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

can somebody help me

Anderies avatar Mar 17 '20 02:03 Anderies

@Anderies , How do you pass in that object body "text": "https://fireship.io and https://www.instagram.com" ?? Do I type it into my terminal window, do I put it in the index.js file, before running 'npm run serve' ? I am a beginner with this webscraping project and firebase, and I am on a mac.

I don't understand how to actually use it.

Thank you for any help!

stanjdev avatar May 11 '20 18:05 stanjdev

@Anderies

I looked back at this project and solved the UnhandledPromiseRejectionWarning here:

https://stackoverflow.com/questions/61784384/firebase-webscraping-project/63494426#63494426

Turns out that JSON.parse() was unnecessary. Do you know what I have to edit in order to scrape another Instagram account? I don't get how to do that part...

stanjdev avatar Aug 19 '20 20:08 stanjdev

I know you run the program by typing in firebase serve or npm run serve in your terminal as you're cd'ed into your 'functions' directory.

So, I was able to get the scrapeImages function working. But in an improper way. I don’t know how to make the actual HTTP request exports.scraper = functions.https.onRequest((request, response) work, because throwing in body.text keeps resulting in undefined

So I opted to simply pass in the literal IG usernames in const data = await scrapeImages(“fireship_dev”); - which works.

I couldn’t get the scrapeText function to work because the HTTP request results in untitled which you’re unable to map over that, so I’m not sure…

stanjdev avatar Aug 19 '20 22:08 stanjdev

got this error after doing post method at postman with object body "text": "https://fireship.io and https://www.instagram.com"

functions: Beginning execution of "scraper"

(node:3216) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token o in JSON at position 1 at JSON.parse () at cors (D:\ANDERIES\LEARN\ws-fireship\functions\index.js:45:27) at cors (D:\ANDERIES\LEARN\ws-fireship\functions\node_modules\cors\lib\index.js:188:7) at D:\ANDERIES\LEARN\ws-fireship\functions\node_modules\cors\lib\index.js:224:17 at originCallback (D:\ANDERIES\LEARN\ws-fireship\functions\node_modules\cors\lib\index.js:214:15) at D:\ANDERIES\LEARN\ws-fireship\functions\node_modules\cors\lib\index.js:219:13 at optionsCallback (D:\ANDERIES\LEARN\ws-fireship\functions\node_modules\cors\lib\index.js:199:9) at corsMiddleware (D:\ANDERIES\LEARN\ws-fireship\functions\node_modules\cors\lib\index.js:204:7) at exports.scraper.functions.https.onRequest (D:\ANDERIES\LEARN\ws-fireship\functions\index.js:42:5) at runFunction (C:\Users\ASUS\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:622:20) (node:3216) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:3216) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

can somebody help me

Probably very late but I just went through this video and had the same problem using postman. If you select the Body tab. The next row below gives you a series of request data input methods.

Select raw then a drop down should appear. Make sure that is set to Text then enter in the input (still wrapped in curly brackets like it has been Stringify-ed)

The other option is to remove the JSON.parse from the scrape function then you can send it as JSON but you will need to add that back at the end when you input data into a text area.

michael-rayner92 avatar Jan 02 '21 11:01 michael-rayner92