Sep 28, 2020 02:31 PM
A simple script to fetch search results from Google based on keywords in your base:
let table = base.getTable('Searches');
let resultsField = table.getField('Results');
let record = await input.recordAsync('Record', table);
let searchQuery = await input.textAsync('Search query');
if (searchQuery) {
table.updateRecordAsync(record, {[resultsField.id]: 'Updating...'});
output.markdown(`Searching for ${searchQuery}...`);
let results = await searchAsync(searchQuery.split(',').map(term => term.trim()).join('\n'));
await table.updateRecordAsync(record, {[resultsField.id]: results});
output.markdown(results);
}
async function searchAsync(searchTerm) {
let response = await fetch(
`https://api.apify.com/v2/actor-tasks/<TASK ID>/run-sync-get-dataset-items?token=<TOKEN>`,
{
method: "POST",
headers: {"content-type": "application/json"},
body: JSON.stringify({queries: searchTerm}),
},
);
let result = await response.json();
let resultLines = [];
for (let {searchQuery, organicResults} of result) {
resultLines.push(`## ${searchQuery.term}`);
for (let {title, url, description} of organicResults) {
resultLines.push(`- [**${title}**:](${url}) ${description}`);
}
}
return resultLines.join('\n');
}
Sep 29, 2020 04:11 AM
Very cool. Have you thought of a way to cleanly output results into another table or individual records?
Seems like this could be used to check a website’s url against these results, and then tell where your website is ranked among google search results. Could be turned into a customized SERP tracker.
Sep 30, 2020 06:13 AM
This script uses Apify’s Google Search Results Scraper—they have a lot of useful building blocks for scripts on their site!
Oct 03, 2020 11:29 AM
Hey @Halley_Johnson this is great! (I think). How might I apply this if I wanted to search for a list of fellow artists’ websites if I have name and I want to search for {FullName} + “Artist” or “Art”?
Oct 08, 2020 08:40 AM
Could this be used to fetch Google Image search results? We’re wanting to pull company logos.
Oct 08, 2020 08:58 AM
@Brian_Swichkow - for company logos, check out clearbits free logo api: https://clearbit.com/logo
Oct 09, 2020 12:31 PM
Thank you @openside!
(1) https://clearbit.com/logo as a formula field with (2) the MIniExtensions bit Convert URLs to Attachments in Bulk on Airtable, and (3) their Cloudinary bit was EXACTLY the recipe I was looking for.
May 12, 2021 01:18 AM
Hello,
Thank you for this usefull script !
I need to only fetch the first result of the google search and only the URL not the title or the description.
What are the modifications to do in the script please ?
Thank you !!