linkedin爬虫_我是如何使LinkedIn接触者添加机器人的-实际得到了一些采访

linkedin爬虫

by YK Sugi

由YK Sugi

我是如何使LinkedIn联系人添加机器人的,并自动获得了一些采访 (How I made a LinkedIn contact adding bot - and automatically got a few interviews with it)

On LinkedIn, there’s a section that’s titled, “People you may know.” It’s under the My Network tab.

在LinkedIn上,有一个标题为“您可能认识的人”的部分。 在“ 我的网络”标签下。

This is the page that suggests people you might want to connect with.

这是向您推荐可能需要联系的人的页面。

You can click these Connect buttons to send connection requests to the people in this list.

您可以单击这些“ 连接”按钮将连接请求发送给此列表中的人员。

A few years ago, I found this page, and I started randomly adding people there. I would just click on the connect button on every single person I found on this page.

几年前,我找到了此页面,并开始在这里随机添加人员。 我只要在此页面上找到的每个人上单击“连接”按钮即可。

I just figured it might be useful to have a lot of connections on LinkedIn to get the kinds of jobs I wanted to get, for example, software engineer internships.

我只是觉得在LinkedIn上建立大量联系以获取我想获得的各种工作(例如软件工程师实习)可能会有用。

But after a while, it became a little bit cumbersome to keep clicking on these connect buttons manually.

但是过了一会儿,手动继续单击这些连接按钮变得有点麻烦。

So, I decided to make a little bot to click these buttons for me.

因此,我决定制作一个小机器人来为我单击这些按钮。

This is an article about how I made this bot, what happened as a result, and what I learned from it.

这篇文章介绍了我如何制作该机器人,发生了什么以及从中学到了什么。

我是如何制作机器人的 (How I made the bot)

我使用的工具 (The tools I used)

I made this simple bot to add random people on LinkedIn with JavaScript and Greasemonkey.

我制作了这个简单的机器人,使用JavaScriptGreasemonkey在LinkedIn上添加了随机对象。

Greasemonkey is a Firefox add-on that helps you manage custom JavaScript code.

Greasemonkey是Firefox的附加组件,可帮助您管理自定义JavaScript代码。

With it, you can set things up so that a certain set of code runs automatically when you open a certain URL.

借助它,您可以进行设置,以便在打开特定URL时自动运行特定代码集。

You can also store some data in Greasemonkey. I used this feature to keep track of the number of people I added with this bot. That way, I was able to keep track of this number consistently even when I closed the browser or refreshed the page.

您也可以在Greasemonkey中存储一些数据。 我使用此功能来跟踪使用此机器人添加的人数。 这样,即使关闭浏览器或刷新页面,我也能够始终如一地跟踪此数字。

我使用的代码 (The code I used)

Unfortunately, I did not keep the code I used to create my bot after I used it.

不幸的是,使用后我没有保留用于创建机器人的代码。

So, in this article, I’ll do my best to recreate it as closely as possible.

因此,在本文中,我将尽我所能尽可能地重新创建它。

Initially, to create this bit of code, I used Google Chrome. Later, I switched to Firefox to use Greasemonkey, which I mentioned earlier. I chose to use Chrome initially just because I was more used to it.

最初,为了创建这段代码,我使用了Google Chrome。 后来,我切换到Firefox来使用我前面提到的Greasemonkey。 我最初选择使用Chrome只是因为我已经习惯了。

Now, let’s together go through how I would recreate this code today. In this article, just to keep it simple, I’m only going to show you the core functionality of this bot - adding people. So, I’m going to skip the part about using Greasemonkey to store data persistently here.

现在,让我们一起探讨如何重新创建此代码。 在本文中,为简单起见,我仅向您展示该机器人的核心功能-增加人员。 因此,在这里我将跳过有关使用Greasemonkey持久存储数据的部分。

Please let me know in the comments if you’d like me to cover that part in a separate article.

如果您希望我在另一篇文章中介绍该部分,请在评论中让我知道。

步骤0:JavaScript基础知识 (Step 0: JavaScript basics)

In case you’re not too familiar with JavaScript, let’s quickly go over some JavaScript basics here.

如果您不太熟悉JavaScript,让我们在这里快速介绍一些JavaScript基础知识。

We’re going to use Google Chrome here, but you can use any browser you’d like to use.

我们将在这里使用Google Chrome,但您可以使用任何想要使用的浏览器。

First, open any website, let’s say, Google.com.

首先,打开任何网站,比方说Google.com。

Then, you’ll need to open the browser’s JavaScript console there.

然后,您需要在此处打开浏览器JavaScript控制台。

On Google Chrome, you can do it in a few different ways.

在Google Chrome浏览器上,您可以通过几种不同的方式进行操作。

The way I usually do it is the following:

我通常的操作方式如下:

  • Right click anywhere on the page.

    右键单击页面上的任意位置。
  • Then, click Inspect out of the menu that’s popped up.

    然后,从弹出菜单中单击检查

  • When you click it, a window like the following should show up.

    当您单击它时,将出现如下所示的窗口。
  • Then, click the Console tab there to show the JavaScript console.

    然后,单击那里的“ 控制台”选项卡以显示JavaScript控制台。

  • Once you click the Console tab, you should see the JavaScript console.

    单击“ 控制台”选项卡后,应该会看到JavaScript控制台。

This is where you can type in any JavaScript code to test it. You can use the code you enter to interact with the page that’s open in your browser.

您可以在此处输入任何JavaScript代码进行测试。 您可以使用输入的代码与浏览器中打开的页面进行交互。

For example, try typing in the following code in the console and press Enter.

例如,尝试在控制台中输入以下代码,然后按Enter。

selected = document.querySelector('body');

This selects the body tag in the page that’s open on the browser. Then, it assigns it to a new variable called selected.

这将在浏览器中打开的页面中选择body标签。 然后,将其分配给名为selected的新变量。

In Chrome and Firefox, there is a shorthand for:

在Chrome和Firefox中,存在以下简称:

selected = document.querySelector('body');

Instead, you can just write:

相反,您可以编写:

selected = $('body');

This code is equivalent to the one above.

此代码与上面的代码等效。

I’m going to use this shorthand notation with the dollar sign throughout this article to keep our code short and simple.

在本文中,我将使用带$的简写形式来使我们的代码简短。

Also, don’t worry about it if you don’t know the basics of HTML and JavaScript yet. I’ll try my best to write this article so it’s easy to understand even for beginners.

另外,如果您还不了解HTML和JavaScript的基础知识,也不必担心。 我会尽力写这篇文章,这样即使对于初学者也很容易理解。

If you’re not interested in the code I’m going to show you, you can also just skip to the sections about what happened and what I learned from this experience at the end.

如果您对我要向您展示的代码不感兴趣,那么您也可以直接跳到有关发生了什么以及最后从这次经验中学到的知识的部分。

Now, let’s walk through our bot’s code, step by step.

现在,让我们逐步介绍我们的机器人代码。

步骤1:找到目标元素 (Step 1: Find the target element)

First, you’ll need to write the bit of code that finds the buttons that you want to click.

首先,您需要编写一些代码来查找要单击的按钮。

First, log in to LinkedIn. Then, go to the My Network tab. It’s currently at https://www.linkedin.com/mynetwork/ (July, 2018).

首先,登录LinkedIn。 然后,转到“我的网络”选项卡。 当前位于https://www.linkedin.com/mynetwork/(2018年 7月)。

You should be able to find the People you may know section there.

您应该可以在此处找到您可能认识的人部分。

Then, on Chrome, right click on the “connect” button on one of the recommended people there. Then, click Inspect.

然后,在Chrome上,右键单击那里推荐的人之一上的“连接”按钮。 然后,单击检查

Once you do so, the element that you just clicked on will be highlighted in the developer window.

完成后,您刚刚单击的元素将在开发人员窗口中突出显示。

This is the HTML code that’s highlighted in blue here:

这是在此处以蓝色突出显示HTML代码:

<span aria-hidden=”true”>Connect</span>

This is a span tab that shows the text: Connect. What we really want to click on is not this one, but its parent element, which is a button.

这是一个显示文本的跨度选项卡: Connect 。 我们真正想要单击的不是此元素,而是其父元素,即按钮。

You can find it right above the span element that we selected.

您可以在我们选择的span元素上方找到它。

Let’s now examine this button element:

现在让我们检查一下此按钮元素:

<button data-control-name=”invite” class=”button-secondary-small” data-ember-action=”” data-ember-action-1596=”1596" data-is-animating-click=”true”> <span aria-hidden=”true”>Connect</span> <span class=”visually-hidden”> Invite Azul Pinochet Barros to connect </span></button>

There’s a bunch of stuff here, but here’s the important part:

这里有很多东西,但这是重要的部分:

<button data-control-name=”invite” ...> <span aria-hidden=”true”>Connect</span> ...</button>

Basically, this is a button element whose attribute, data-control-name, is “invite”.

基本上,这是一个按钮元素,其属性data-control-name为“邀请”。

In our script, all we need to do is select elements like this and click them.

在脚本中,我们要做的就是选择像这样的元素并单击它们。

You can select these elements with this piece of code:

您可以通过以下代码选择这些元素:

selected = $(“button[data-control-name=invite]”);

This reads as, select all the button elements whose data-control-name is “invite”.

读取为,选择其data-control-name为“ invite”的所有按钮元素。

NOTE: It looks like LinkedIn’s website uses jQuery. So, the notation above is actually a jQuery selector, not a helper function defined by Chrome. Confusingly, their behaviours are slightly different ?

注意:看起来LinkedIn的网站使用jQuery。 因此,以上表示法实际上是jQuery选择器, 而不是Chrome定义的辅助函数 令人困惑的是,他们的行为略有不同?

Anyway, once you run this code in your Chrome console, you should be able to see that the correct elements have been selected.

无论如何,在Chrome控制台中运行此代码后,您应该能够看到已选择了正确的元素。

Now, with this piece of code - selected = $("button[data-control-name=invite]"); - your browser finds multiple button elements and puts them in an array. To pick the first one, you can just select the first element in this array like so:

现在,使用这段代码selected = $("button[data-control-name=invite]"); -您的浏览器会找到多个按钮元素,并将它们放入数组中。 要选择第一个元素,只需选择此数组中的第一个元素,如下所示:

toClick = $("button[data-control-name=invite]")[0];

Then, you can click it with this:

然后,您可以使用以下命令单击它:

toClick.click();

If it goes through, you should see a confirmation window popping up.

如果通过,您将看到弹出确认窗口。

步骤2:遍历多个目标元素 (Step 2: Loop through multiple target elements)

Now, the next step is to loop through multiple target elements to click so we can add multiple people.

现在,下一步是遍历多个目标元素以单击,以便我们可以添加多个人员。

After some experimentation, I realized that there’s a simpler way to select multiple buttons and loop through them than the one I showed earlier.

经过一些实验,我意识到比起先前显示的按钮,有一种更简单的方法来选择多个按钮并遍历它们。

Here’s how I would do it.

这就是我的做法。

First, use Inspect Element to analyze the structure of this page a bit more. Then, you should be able to see that the people you may know is just an unordered list.

首先,使用Inspect Element进一步分析此页面的结构。 然后,您应该能够看到您可能认识 只是一个无序列表。

You should be able to find code that looks like this:

您应该能够找到如下所示的代码:

The parent element is a ul (unordered list) element. Its children are li (list item) elements.

父元素是ul (无序列表)元素。 它的子元素是li (列表项)元素。

Each li element represents each of the people you may know cards you see on the screen.

每个li元素代表您可能认识的每个在屏幕上看到的卡片的

By selecting these li elements instead of selecting the buttons directly, it actually becomes easier to go through multiple people.

通过选择这些li元素而不是直接选择按钮,实际上可以更轻松地遍历多个人。

You can select this ul element, the parent of the li elements, like this:

您可以选择以下ul元素( li元素的父元素),如下所示:

ul = $('ul.mn-pymk-list__cards')[0];

This says, select the ul element with the class ul.mn-pymk-list__cards. We need to add [0] at the end because the raw result is an array containing a single element.

ul.mn-pymk-list__cards ,选择类ul.mn-pymk-list__cardsul元素。 我们需要在末尾添加[0] ,因为原始结果是一个包含单个元素的数组。

Then, you can select the first li element (the first person’s card) under the ul element like this:

然后,您可以像下面这样在ul元素下选择第一个li元素(第一个人的卡):

firstLi = ul.querySelector('li');

We don’t need to add [0] at the end of this statement because the querySelector() function only returns one element.

我们不需要在该语句的末尾添加[0] ,因为querySelector()函数仅返回一个元素。

Then, out of firstLi, you can select the button that we need to click like this:

然后,从firstLi ,您可以选择我们需要单击的按钮,如下所示:

buttonToClick = firstLi.querySelector("button[data-control-name=invite]");

After clicking this button with buttonToClick.click(), we should remove this li element so we can go to the next li element (the next person’s card). We can do that with this:

在使用buttonToClick.click()单击此按钮之后,我们应该删除此li元素,以便可以转到下一个li元素(下一个人的卡)。 我们可以这样做:

ul.removeChild(firstLi);

Putting them all together, and putting everything in a while loop, you’ll get something like this:

将它们放在一起,然后将所有内容放入一个while循环,您将获得如下内容:

ul = $('ul.mn-pymk-list__cards')[0];firstLi = ul.querySelector('li');while(firstLi){ // do this while firstLi still exists.  buttonToClick = firstLi.querySelector("button[data-control-name=invite]");  ul.removeChild(firstLi);  firstLi = ul.querySelector('li');}

This code should work, but it has several issues.

该代码应该可以工作,但是有几个问题。

  1. We add people really fast with this, so it’s going to be hard to know what’s going on when you run this code.

    我们确实很快地添加了人员,因此在运行此代码时将很难知道发生了什么。

  2. We are not keeping track of how many people we’ve added.

    我们不跟踪添加了多少人。
  3. We are assuming that buttonToClick is always the correct button to click. Sometimes this button has the text “Invite” instead of “Connect”. We don’t want to click on too many of those “Invite” buttons.

    我们假设buttonToClick始终是正确的单击按钮。 有时,此按钮的文字为“邀请”而不是“连接”。 我们不想单击太多的“邀请”按钮。

步骤3:完善代码 (Step 3: Refine our code)

I’ve fixed all of the issues I mentioned above and put together a relatively simple piece of code below.

我已经修复了上面提到的所有问题,并在下面整理了一个相对简单的代码。

It’s also here on Gist. Perhaps it’s easier to read there.

这也是这里的要点。 也许在那里更容易阅读。

// this function allows us to stop our code for |ms| milliseconds.function sleep(ms) {  return new Promise(resolve => setTimeout(resolve, ms));}
// I've put our main code into this function.async function addPeople() {  ul = $('ul.mn-pymk-list__cards')[0];  firstLi = ul.querySelector('li');  count = 0; // this is the count of how many people you've added  while(firstLi && count < 100){ // stop after adding 100 people    buttonToClick = firstLi.querySelector("button[data-control-name=invite]");    // make sure that this button contains the text "Connect"    if (buttonToClick.innerText.includes("Connect")){      buttonToClick.click();      count += 1;      console.log("I have added " + count + " people so far.");    }    ul.removeChild(firstLi);    await sleep(1000); // stop this function for 1 second here.    firstLi = ul.querySelector('li');  }}
addPeople();

If you examine this code carefully, you should be able to notice the couple of changes I’ve made:

如果仔细检查此代码,您应该能够注意到我所做的几处更改:

  1. I’ve put our code into an async function called addPeople(). In this function, every time we add someone, we pause for 1 second with the sleep() function. More about this pattern here.

    我已经将我们的代码放入了一个名为addPeople()的异步函数中。 在此函数中,每次添加某人时,我们都会使用sleep()函数暂停1秒钟。 有关此模式的更多信息,请参见

  2. I added a count variable to keep track of how many people we’ve added.

    我添加了一个count变量来跟踪我们添加了多少人。

  3. I added this if statement: if (buttonToClick.innerText.includes("Connect"){...}. This way, we can make sure that the button we’re clicking contains the word “Connect” inside it.

    我添加了以下if语句: if (buttonToClick.innerText.includes("Connect"){...} 。通过这种方式,我们可以确保所单击的按钮中包含“ Connect”一词。

With these changes, when I run this code, it looks like this:

经过这些更改,当我运行此代码时,它看起来像这样:

步骤4:进一步改进! (Step 4: Make further improvements!)

On top of what I showed above, I had a few more functionalities when I actually used my bot to add a bunch of people on LinkedIn.

除了上面显示的内容以外,当我实际使用我的机器人在LinkedIn上添加一群人时,我还具有一些其他功能。

First of all, I used Greasemonkey, which I mentioned earlier, to keep track of the total number of people I’ve added.

首先,我使用了前面提到的Greasemonkey来跟踪我添加的人员总数。

Also, to avoid being detected as a bot by LinkedIn, I added a few things:

另外,为了避免被LinkedIn识别为机器人,我添加了几件事:

  1. I randomized the order in which I added people.

    我随机分配了添加人员的顺序。
  2. I randomized the amount of time I waited every time I added a new person.

    每次添加新人时,我都会随机等待的时间。

I’ll leave all of these as exercise problems for you to solve in case you’re interested in solving them ?

如果您有兴趣解决这些问题,我将把所有这些问题留给您解决。

发生了什么 (What happened)

With my script, I ended up adding 2000+ connections. Then, if I remember correctly, about 400 of them added me back.

使用脚本,我最终添加了2000多个连接。 然后,如果我没记错的话,其中约有400人使我加入了。

As a result, I went from about 300 connections to 700+ connections within a week or so!

结果,我在一周左右的时间里从大约300个连接变为了700个以上的连接!

Then, after a while, I got banned by LinkedIn from adding any more people. I didn’t know that I could get banned! I was scared for a bit, but the ban lifted after 2 months or so.

然后,过了一会儿,我被LinkedIn禁止添加任何人。 我不知道我会被禁止! 我有点害怕,但禁令在2个月左右后解除了。

More importantly, I was able to land a few interviews from those 400+ new connections. One of the interviews was with this company called Palantir.

更重要的是,我能够从这400多个新连接中获得一些采访。 采访之一是对这家名为Palantir的公司的采访。

Here’s a screenshot of the message I received from them:

这是我从他们那里收到的消息的屏幕截图:

我从这次经验中学到了什么 (What I learned from this experience)

I thought what I was doing was pretty silly at the time, but I ended up learning a lot from this experience.

我以为当时我的工作很愚蠢,但最终我从这次经历中学到了很多东西。

外卖1 (Takeaway 1)

First of all, through this experience, I realized that LinkedIn actually works for getting jobs. I was able to get a few job interviews with my bot, after all.

首先,通过这种经验,我意识到LinkedIn确实可以找到工作。 毕竟,我能够用我的机器人进行一些工作面试。

Then, after a while, I also realized that adding thousands of random people was not the most efficient way to use LinkedIn. With that kind of approach, you end up adding a lot of people you don’t need to add.

然后,过了一会儿,我也意识到添加数千个随机人并不是使用LinkedIn的最有效方法。 通过这种方法,您最终会添加很多不需要添加的人员。

So, after that experience, I changed my approach to a more focused one.

因此,在经历了这段经历之后,我将我的方法改为了更加专注的方法。

With my new approach, I would only add recruiters of the companies I wanted to work at. Then, I would only send messages to the people who added me back.

使用我的新方法,我只会添加我想工作的公司的招聘人员。 然后,我只会将消息发送给添加了我的人。

It turned out to be a much more focused, effective strategy to use LinkedIn. With this new strategy, I was able to get a few more job interviews with multiple tech companies, including Yelp and Xamarin. This time, I didn’t have to add thousands of new connections to achieve this result ?

事实证明,使用LinkedIn是一种更具针对性,更有效的策略。 通过这种新策略,我得以与包括Yelp和Xamarin在内的多家高科技公司进行了一些面试。 这次,我不必添加成千上万的新连接来获得此结果?

NOTE: I talk more about this strategy in this article, just in case you’re curious about it.

注意:在本文中 ,我会更多地讨论此策略,以防万一您对此感到好奇。

外卖2 (Takeaway 2)

Having fun is the best way to hone your programming skills!

开心是磨练您的编程技能的最佳方式!

Through this particular project, I was able to hone my JavaScript skills. What I learned included:

通过这个特定的项目,我能够磨练我JavaScript技能。 我学到的包括:

  • How to set a timed interval between function executions

    如何设置函数执行之间的时间间隔
  • How to select certain HTML elements with JavaScript

    如何使用JavaScript选择某些HTML元素
  • How to store data locally with Greasemonkey

    如何使用Greasemonkey在本地存储数据

I learned these things through this project, and it didn’t feel like studying at all because it was so much fun.

我通过这个项目学到了这些东西,因为它非常有趣,所以根本不想学习。

外卖3 (Takeaway 3)

From this experience, I’ve learned that it sometimes pays to do something weird. So, don’t be afraid of being a little bit mischievous and adventurous if you have any inclination to do so.

从这种经验中,我了解到有时候做一些奇怪的事情是值得的。 因此,如果您愿意这样做,不要害怕有点调皮和冒险。

Even after this little experiment, I continued to do weird things for fun.

即使经过了这个小实验,我仍然继续做一些奇怪的事情。

For example, when I was interning at Microsoft, I ran a little experiment where I “stole” a bunch of employee passwords. I did that by sending out a phishing email. It was supposed to be a huge give-away raffle with prizes like Xbox and Surface laptops. It was my hackathon project there.

例如,当我在Microsoft实习时,我做了一个小实验,“偷走”了一堆员工密码。 我是通过发送网络钓鱼电子邮件来做到这一点的。 这本来应该是巨大的抽奖活动,其中包括Xbox和Surface笔记本电脑之类的奖品。 那是我在那里的黑客马拉松项目。

I also started a programming-education YouTube channel, and eventually decided to work on it full-time and quit my full-time software engineer job.

我还开设了一个编程教育YouTube频道 ,最终决定全职从事该 频道并辞去了我的专职软件工程师工作

Perhaps all of these things seemed a little bit weird to other people. But every time I went through each of these experiences, I learned something new, and I had tons of fun along the way. I would say the last one even made my career.

也许所有这些事情对其他人来说似乎有些奇怪。 但是每次经历这些经历时,我都会学到一些新的东西,并且在此过程中我会获得很多乐趣。 我会说最后一个甚至使我成为了职业。

So again, don’t be afraid of trying something strange just for fun! You might learn something valuable along the way.

再次重申,不要害怕为了娱乐而尝试一些奇怪的事情! 在此过程中,您可能会学到一些有价值的东西。

好的,仅此而已。 (Okay, that’s it for this article.)

This was supposed to be sort of a fun article, but I usually write about more serious stuff.

本来应该是一篇有趣的文章,但是我通常会写一些更严肃的文章。

For example, I have articles about writing your software engineer resume, the best ways to apply for software engineer jobs, and how to get a job at a top tech company.

例如,我有关于写您的软件工程师简历申请软件工程师职位的最佳方法以及如何在顶级高科技公司找到工作的文章

Feel free to check them out. They are all here on Medium.

随时检查他们。 他们都在这里。

Also, as always, if you have any questions about this or anything else, please feel free to let me know in a comment below or on Instagram or Twitter (@ykdojo on both).

此外,与往常一样,如果您对此有任何疑问,请随时在下面的评论中或在InstagramTwitter (两者均为@ykdojo)上让我知道。

Thank you for reading this article!

感谢您阅读本文!

翻译自: https://www.freecodecamp.org/news/how-i-made-a-linkedin-contact-adding-bot-and-actually-got-a-few-interviews-with-it-37a6f5f85d4d/

linkedin爬虫

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值