start urls input
I can get the input from Apify in my Crawlee Playwright code and console.log() the start urls, but I am not sure how to access them because it says the start urls are of type any instead of an array of strings. Can you provide some example code for this to be extracted so I can use them as start urls in my code?
19 Replies
Hi @Casper ,
I am not sure if I understand, You should be able to set the type of the input as:
thanks, how can I add the start urls to this code?
I read input like this at the moment
Then convert to Array of strings:
You mean sometihng like this? I would not recomend using
as operator when it is not necessary.
yes, something like this: `
I will convert to the schema interface as well later
I have converted to input schema now but it does not work
RROR Received one or more errors
Error: Received one or more errors
at ArrayValidator.handle (C:\Development\ApifyWebscrapers\crawlee-trustpilot-review-actor\node_modules@sapphire\shapeshift\src\validators\ArrayValidator.ts:21:14)
what do you have in
INPUT.json and input_schema.json?INPUT.json
So maybe you need:
apify vis
NOT SUPPORTED: option cache. Map is used as cache, schema object as key. Error: Input schema is not a valid JSON (SyntaxError: Unexpected token } in JSON at position 458)
NOT SUPPORTED: option cache. Map is used as cache, schema object as key. Error: Input schema is not a valid JSON (SyntaxError: Unexpected token } in JSON at position 458)
And the
companyWebsites should be array of objects:
in INPUT.json
arh, can I change it to just array of strings?
I fixed schema now
but still not array
The attribute in
input_schema.json requires the format with objects:
If you want to use array of string you have to use different editor like:
ok
what would be the easiest for me and my customer?
I am not sure if I follow. Using Is totally fine but it requires, the specific format of input. You mentioned you need different input, so I suggested you to use plain JSON editor for it. I don't know your customer, there are plenty options, you may check https://docs.apify.com/platform/actors/development/actor-definition/input-schema/specification/v1
Specification (v1) | Apify Documentation
Learn how to define and easily validate a schema for your Actor's input with code examples. Provide an autogenerated input UI for your Actor's users.
thanks it works now, but how can I use label with startUrl()?
await crawler.run(startUrls);
Hmm.. you may use the
.map to hardcode the single label it as I already mentioned.map just skips the next url in the array
What do you mean by that?
hmm it seems to work, I will check tomorrow, thanks 🙂