使用 Python 访问 LinkedIn 公共页面 [英] Accessing LinkedIn public pages using Python

查看:28
本文介绍了使用 Python 访问 LinkedIn 公共页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想访问我公开的 LinkedIn 页面.在我的本地机器上,以下代码有效:

I want to access my publicly available LinkedIn page. On my local machine, following code works:

import requests
url = "http://de.linkedin.com/pub/ankush-shah/73/9/982"
html = requests.get(url).text
print html

它提供了我个人资料的正确 html.

And it gives the correct html of my profile.

但是当我在 Heroku 服务器上执行相同的代码时,我(猜测)被重定向到某个地方并获得 this html.

But when I execute the same code on my Heroku server, I (guess) am redirected to somewhere and gets this html.

此外,当我在 heroku 服务器上尝试使用 urllib2 时:

Also, when I try with urllib2 on the heroku server:

import urllib2
url = "http://de.linkedin.com/pub/ankush-shah/73/9/982"
u = urllib2.urlopen(url)

这会抛出一个 urllib2.HTTPError: HTTP Error 999: Request denied

当我使用 virtualenv 时,我本地机器上的所有库都与安装在 heroku 服务器上的库完全相似.LinkedIn 是否会阻止来自 Heroku 等服务器的 HTTP 请求?任何帮助/建议将不胜感激.

As I am using virtualenv, all the libraries on my local machine are exactly similar to the one installed on heroku server. Does LinkedIn blocks HTTP requests from servers like Heroku? Any help/suggestions would be appreciated.

推荐答案

如上所述 此处,LinkedIn 不允许直接访问.他们已将 Heroku 的 IP 地址列入黑名单,访问数据的唯一方法是使用他们的 API.

As mention here, LinkedIn do not allow direct access. They have blacklisted Heroku's IP address and the only way to access the data is to use their APIs.

这篇关于使用 Python 访问 LinkedIn 公共页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆