1from apify_client import ApifyClient
2
3
4
5client = ApifyClient("<YOUR_API_TOKEN>")
6
7
8run_input = { "scrapyCode": """import scrapy
9import apify
10
11class MySpider(scrapy.Spider):
12 \tname = 'apifySpider'
13
14 \tdef start_requests(self):
15 \t\turls = [
16 \t\t\t'https://apify.com',
17 \t\t\t'https://apify.com/store',
18 \t\t]
19 \t\tfor url in urls:
20 \t\t\tyield scrapy.Request(url=url, callback=self.parse)
21
22 \tdef parse(self, response):
23 \t\turl = response.url
24 \t\ttitle = response.css('title::text').get()
25 \t\toutput = {
26 \t\t\t'url': url,
27 \t\t\t'title': title
28 \t\t}
29 \t\tapify.pushData(output)""" }
30
31
32run = client.actor("apify/scrapy-executor").call(run_input=run_input)
33
34
35print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
36for item in client.dataset(run["defaultDatasetId"]).iterate_items():
37 print(item)
38
39