Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
refactor!: remove the Google Sheets URL rewrite from `downloadListOfUrls` (#4377)
Jindřich Bär2648bc8f3462
diff --git a/docs/upgrading/upgrading-v4/upgrading-v4.md b/docs/upgrading/upgrading-v4/upgrading-v4.mdindex 61820417c..47fb2b78b 100644--- a/docs/upgrading/upgrading-v4/upgrading-v4.md+++ b/docs/upgrading/upgrading-v4/upgrading-v4.md@@ -300,6 +300,10 @@ Reading the run input is an Apify platform concern, so Crawlee no longer has any- **`Configuration.inputKey` and the `CRAWLEE_INPUT_KEY` environment variable are removed.** The Apify SDK's `Configuration` defines `inputKey` itself.- **The default key-value store is purged in full**, `INPUT` included. Sparing a key, and claiming a bare `<key>` / `<key>.json` file as the record `<key>` (see [Out-of-band key-value files](#out-of-band-key-value-files-eg-a-hand-placed-inputjson)), is left to subclasses of `FileSystemStorageBackend` through its two protected hooks, `keyValueStoreAdoptionCandidates` and `purgeKeyValueStore`. The Apify SDK's `ApifyFileSystemStorageBackend` does this for its run input; plain Crawlee treats a hand-placed `INPUT.json` as any other file.+### Google Sheets sharing links are no longer rewritten++`downloadListOfUrls()` and `requestsFromUrl` sources no longer turn a Google Sheets sharing link into the link of its CSV export. `Actor.getInput()` from `apify` does this for the Actor input now; elsewhere, use the CSV export link (`https://docs.google.com/spreadsheets/d/<id>/gviz/tq?tqx=out:csv`) directly.+### Service management moved from `Configuration` to `ServiceLocator`The service management functionality has been extracted from `Configuration` into a new `ServiceLocator` class.diff --git a/packages/utils/src/internals/extract-urls.ts b/packages/utils/src/internals/extract-urls.tsindex 6a47cfeb6..41c0e7b69 100644--- a/packages/utils/src/internals/extract-urls.ts+++ b/packages/utils/src/internals/extract-urls.ts@@ -54,15 +54,7 @@ export interface DownloadListOfUrlsOptions {export async function downloadListOfUrls(options: DownloadListOfUrlsOptions): Promise<string[]> {const { url, encoding, urlRegExp, proxyUrl, httpClient } = parseArgument(options, downloadListOfUrlsOptionsSchema);- // Try to detect wrong urls and fix them. Currently, detects only sharing url instead of csv download one.- const match = /^(https:\/\/docs\.google\.com\/spreadsheets\/d\/(?:\w|-)+)\/?/.exec(url);- let fixedUrl = url;-- if (match) {- fixedUrl = `${match[1]}/gviz/tq?tqx=out:csv`;- }-- const response = await httpClient.sendRequest(new Request(fixedUrl, { method: 'GET' }), {+ const response = await httpClient.sendRequest(new Request(url, { method: 'GET' }), {proxyUrl,});diff --git a/test/core/request-list.test.ts b/test/core/request-list.test.tsindex d908dee24..039692d36 100644--- a/test/core/request-list.test.ts+++ b/test/core/request-list.test.ts@@ -216,33 +216,6 @@ describe('RequestList', () => {expect(mockHttpClient.sendRequest.mock.calls[0][0].url).toBe('http://example.com/list-1');});- test('should fix gdoc sharing url in `requestsFromUrl` automatically (GH issue #639)', async () => {- const list = ['https://example.com', 'https://google.com', 'https://wired.com'];- const wrongUrls = [- 'https://docs.google.com/spreadsheets/d/11UGSBOSXy5Ov2WEP9nr4kSIxQJmH18zh-5onKtBsovU',- 'https://docs.google.com/spreadsheets/d/11UGSBOSXy5Ov2WEP9nr4kSIxQJmH18zh-5onKtBsovU/',- 'https://docs.google.com/spreadsheets/d/11UGSBOSXy5Ov2WEP9nr4kSIxQJmH18zh-5onKtBsovU/edit?usp=sharing',- 'https://docs.google.com/spreadsheets/d/11UGSBOSXy5Ov2WEP9nr4kSIxQJmH18zh-5onKtBsovU/123123132',- 'https://docs.google.com/spreadsheets/d/11UGSBOSXy5Ov2WEP9nr4kSIxQJmH18zh-5onKtBsovU/?q=blablabla',- 'https://docs.google.com/spreadsheets/d/11UGSBOSXy5Ov2WEP9nr4kSIxQJmH18zh-5onKtBsovU/edit#gid=0',- ];- const correctUrl =- 'https://docs.google.com/spreadsheets/d/11UGSBOSXy5Ov2WEP9nr4kSIxQJmH18zh-5onKtBsovU/gviz/tq?tqx=out:csv';-- mockHttpClient.sendRequest.mockImplementation(async () => new Response(list.join('\n')));-- const requestList = await RequestList.open({- sources: wrongUrls.map((requestsFromUrl) => ({ requestsFromUrl })),- httpClient: mockHttpClient,- });-- expect(await requestList.fetchNextRequest()).toMatchObject({ method: 'GET', url: list[0] });- expect(await requestList.fetchNextRequest()).toMatchObject({ method: 'GET', url: list[1] });- expect(await requestList.fetchNextRequest()).toMatchObject({ method: 'GET', url: list[2] });-- expect(mockHttpClient.sendRequest.mock.calls[0][0]?.url).toBe(correctUrl);- });-test('should handle requestsFromUrl with no URLs', async () => {mockHttpClient.sendRequest.mockResolvedValueOnce(new Response(''));diff --git a/test/core/storages/request-queue.test.ts b/test/core/storages/request-queue.test.tsindex d1c1107e5..5ed6fd950 100644--- a/test/core/storages/request-queue.test.ts+++ b/test/core/storages/request-queue.test.ts@@ -536,34 +536,6 @@ describe('RequestQueue with requestsFromUrl', () => {expect(mockHttpClient.sendRequest.mock.calls[0][0].url).toBe('http://example.com/list-1');});- test('should fix gdoc sharing url in `requestsFromUrl` automatically (GH issue #639)', async () => {- const list = ['https://example.com', 'https://google.com', 'https://wired.com'];- const wrongUrls = [- 'https://docs.google.com/spreadsheets/d/11UGSBOSXy5Ov2WEP9nr4kSIxQJmH18zh-5onKtBsovU',- 'https://docs.google.com/spreadsheets/d/11UGSBOSXy5Ov2WEP9nr4kSIxQJmH18zh-5onKtBsovU/',- 'https://docs.google.com/spreadsheets/d/11UGSBOSXy5Ov2WEP9nr4kSIxQJmH18zh-5onKtBsovU/edit?usp=sharing',- 'https://docs.google.com/spreadsheets/d/11UGSBOSXy5Ov2WEP9nr4kSIxQJmH18zh-5onKtBsovU/123123132',- 'https://docs.google.com/spreadsheets/d/11UGSBOSXy5Ov2WEP9nr4kSIxQJmH18zh-5onKtBsovU/?q=blablabla',- 'https://docs.google.com/spreadsheets/d/11UGSBOSXy5Ov2WEP9nr4kSIxQJmH18zh-5onKtBsovU/edit#gid=0',- ];- const correctUrl =- 'https://docs.google.com/spreadsheets/d/11UGSBOSXy5Ov2WEP9nr4kSIxQJmH18zh-5onKtBsovU/gviz/tq?tqx=out:csv';-- mockHttpClient.sendRequest.mockImplementation(async () => new Response(list.join('\n'), { status: 200 }));-- const queue = await RequestQueue.open(null, {- httpClient: mockHttpClient,- });- await queue.addRequests(wrongUrls.map((requestsFromUrl) => ({ requestsFromUrl })));-- expect(await queue.fetchNextRequest()).toMatchObject({ method: 'GET', url: list[0] });- expect(await queue.fetchNextRequest()).toMatchObject({ method: 'GET', url: list[1] });- expect(await queue.fetchNextRequest()).toMatchObject({ method: 'GET', url: list[2] });-- expect(mockHttpClient.sendRequest.mock.calls[0][0].url).toBe(correctUrl);- await queue.drop();- });-test('should handle requestsFromUrl with no URLs', async () => {mockHttpClient.sendRequest.mockResolvedValueOnce(new Response(''));