HARPA.AI
LIBRARYAPIGUIDESAI COMMANDSBLOG

๐Ÿ”—ย ย LinkedIn Auto Search & Connect

Automatically sends LinkedIn connection requests. First, search and filter for the people you're interested in. Then run this command on the results page to send connection requests. #make #grid #linkedin

Created by HARPA AI
Updated on Feb 11, 08:56
Installed 291 times
RUNS JS CODE

How to Use

IMPORT COMMAND

Content

- type: say
  message: >-
    ๐Ÿ’ก First, search and filter for the people you're interested in. Then run
    this command on the results page to send connection requests.


    Please note that your LinkedIn interface needs to be set to English.
- type: ask
  param: targetProfileCount
  message: |-
    How many LinkedIn profiles would you like to connect with? 

    LinkedIn typically limits you to connecting with ~30 users per day.
  options:
    - label: ๐Ÿ‘ค10
      value: 10
    - label: ๐Ÿ‘ฅ30
      value: 30
    - $custom
  default: ''
  vision:
    enabled: false
    mode: area
    send: true
    hint: ''
  optionsInvalid: false
- type: js
  code: |
    async function connectToProfiles(targetProfileCount) {
        const selectors = {
            nextButton: '.artdeco-pagination--has-controls .artdeco-button:nth-of-type(2)',
            profileList: '[role="list"]',
            profileContainer: 'li',
            name: 'span[aria-hidden="true"]',
            status: '.t-14.t-black.t-normal',
            link: 'a[data-test-app-aware-link]',
            sendButton: '.artdeco-modal__actionbar button:last-child'
        };

        const profiles = [];
        const processedLinks = new Set();

        // Helper function to wait
        const wait = ms => new Promise(resolve => setTimeout(resolve, ms));

        // Click Connect and Send buttons
        async function connectAndSend() {
            // Find the most common button text, with preference for "Connect"
            const buttonFrequency = {};
            let maxCount = 0;
            let mostCommonText = null;

            Array.from(document.querySelectorAll('div.linked-area button > .artdeco-button__text'))
                .map(btn => btn.innerText)
                .forEach(text => {
                    buttonFrequency[text] = (buttonFrequency[text] || 0) + 1;
                    if (buttonFrequency[text] > maxCount) {
                        maxCount = buttonFrequency[text];
                        mostCommonText = text;
                    }
                });

            // Override with "Connect" if it exists
            if (buttonFrequency['Connect']) {
                mostCommonText = 'Connect';
            }

            // Find all buttons with the most common text and filter out muted buttons
            const connectButtons = Array.from(document.querySelectorAll('div.linked-area button > .artdeco-button__text'))
                .filter(btn => {
                    return btn.innerText === mostCommonText && 
                           !btn.closest('button').classList.contains('artdeco-button--muted');
                })
                .map(btn => btn.closest('button'));

            if (!connectButtons.length) return false;

            // Click the first valid connect button
            connectButtons[0].click();
            await wait(1000);

            const sendButton = document.querySelector(selectors.sendButton);
            if (sendButton) {
                sendButton.click();
                return true;
            }
            return false;
        }

        // Process profiles on current page
        async function processCurrentPage() {
            const containers = document.querySelectorAll(`${selectors.profileList} ${selectors.profileContainer}`);

            for (const container of containers) {
                // Stop if target count reached
                if (profiles.length >= targetProfileCount) return true;

                try {
                    const link = container.querySelector(selectors.link).href.split('?')[0];
                    
                    // Skip if already processed
                    if (processedLinks.has(link)) continue;

                    // Try to connect
                    if (await connectAndSend()) {
                        profiles.push({
                            name: container.querySelector(selectors.name)?.textContent.trim() || 'No name',
                            status: container.querySelector(selectors.status)?.textContent.trim() || 'No status',
                            link: link
                        });
                        processedLinks.add(link);
                        await wait(2000); // Wait between connections
                    }
                } catch (error) {
                    console.log('Error processing profile:', error);
                }
            }

            return false;
        }

        // Main loop
        while (profiles.length < targetProfileCount) {
            const isComplete = await processCurrentPage();
            if (isComplete) break;

            // Try to go to next page
            const nextButton = document.querySelector(selectors.nextButton);
            if (!nextButton || nextButton.disabled) break;
            
            nextButton.click();
            await wait(2000);
        }

        console.log(`Connected to ${profiles.length} profiles out of ${targetProfileCount} requested`);
        return profiles;
    }

    return connectToProfiles(targetProfileCount);
  param: json
  timeout: 300000
  args: targetProfileCount
  silent: true
- message: |-
    **Connection request sent:**

    {{json}}
  type: say
- param: action
  options:
    - label: โœ… DONE
      value: done
    - label: ๐Ÿ“ฆ EXPORT JSON
      value: export
  vision:
    enabled: false
    mode: area
    hint: ''
    send: true
  type: ask
  message: ''
  default: ''
  optionsInvalid: false
- type: stop
  condition: '{{action}} = done'
- what: param
  filename: linkedin-group-members.txt
  condition: '{{action}} = export'
  type: export
  param: json
Contact us
HomeUse CasesGuidesPrivacy PolicyTerms of Service
CAN WE STORE COOKIES?
Our website uses cookies for the purposes of accessibility and security. They also allow us to gather statistics in order to improve the website for you. More info: Privacy Policy