- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用anaconda并试图创建一个可以在Linkedin上继续使用并从页面中刮取相关信息的刮刀。目前,我只是想让它登录并从相关页面中提取源代码。但是,下面的代码不断返回“TypeError:'NoneType'对象不可下标”。有谁知道该代码出了什么问题?
import http.cookiejar as cookielib
import os
import urllib
import re
import string
import html5lib
from bs4 import BeautifulSoup
username = "user@email.com"
password = "password"
cookie_filename = "parser.cookies.txt"
class LinkedInParser(object):
def __init__(self, login, password):
""" Start up... """
self.login = login
self.password = password
# Simulate browser with cookies enabled
self.cj = cookielib.MozillaCookieJar(cookie_filename)
if os.access(cookie_filename, os.F_OK):
self.cj.load()
self.opener = urllib.request.build_opener(
urllib.request.HTTPRedirectHandler(),
urllib.request.HTTPHandler(debuglevel=0),
urllib.request.HTTPSHandler(debuglevel=0),
urllib.request.HTTPCookieProcessor(self.cj)
)
self.opener.addheaders = [
('User-agent', ('Mozilla/4.0 (compatible; MSIE 6.0; '
'Windows NT 5.2; .NET CLR 1.1.4322)'))
]
# Login
self.loginPage()
title = self.loadTitle()
print(title)
self.cj.save()
def loadPage(self, url, data=None):
"""
Utility function to load HTML from URLs for us with hack to continue despite 404
"""
# We'll print the url in case of infinite loop
# print "Loading URL: %s" % url
try:
if data is not None:
response = self.opener.open(url, data)
else:
response = self.opener.open(url)
return ''.join([str(l) for l in response.readlines()])
except Exception as e:
# If URL doesn't load for ANY reason, try again...
# Quick and dirty solution for 404 returns because of network problems
# However, this could infinite loop if there's an actual problem
return self.loadPage(url, data)
def loadSoup(self, url, data=None):
"""
Combine loading of URL, HTML, and parsing with BeautifulSoup
"""
html = self.loadPage(url, data)
soup = BeautifulSoup(html, "html5lib")
return soup
def loginPage(self):
"""
Handle login. This should populate our cookie jar.
"""
soup = self.loadSoup("https://www.linkedin.com/")
csrf = soup.find(id="loginCsrfParam-login")['value']
login_data = urllib.parse.urlencode({
'session_key': self.login,
'session_password': self.password,
'loginCsrfParam': csrf,
}).encode('utf8')
self.loadPage("https://www.linkedin.com/uas/login-submit", login_data)
return
def loadTitle(self):
soup = self.loadSoup("http://www.linkedin.com/nhome")
return soup.find("title")
parser = LinkedInParser(username, password)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-24-43815804ad91> in <module>()
87 return soup.find("linked")
88
---> 89 parser = LinkedInParser(username, password)
<ipython-input-24-43815804ad91> in __init__(self, login, password)
34
35 # Login
---> 36 self.loginPage()
37
38 title = self.loadTitle()
<ipython-input-24-43815804ad91> in loginPage(self)
73 """
74 soup = self.loadSoup("https://www.linkedin.com/")
---> 75 csrf = soup.find(id="loginCsrfParam-login")['value']
76 login_data = urllib.parse.urlencode({
77 'session_key': self.login,
TypeError: 'NoneType' object is not subscriptable
最佳答案
看起来像
soup.find(id="loginCsrfParam-login")
LinkedInParser
对象都会尝试登录。它从文件加载cookie:
if os.access(cookie_filename, os.F_OK):
self.cj.load()
# Login
self.loginPage()
['value']
。
if not os.access(cookie_filename, os.F_OK):
self.loginPage()
self.cj.save()
关于python - 使用python创建一个Linkedin Webscraper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31836828/
创建我们的产品 LinkedIn 应用程序的开发人员通过 developer.linkedin.com 在他的个人 LinkedIn 帐户下添加了它。我们想将此应用程序移至我们公司的 LinkedIn
我正在尝试使用linkedin API 来显示我从第一天开始发布的个人资料的提要。帖子包括媒体、图像、视频等。我想知道是否有任何可用的 API,我可以在其中传递一些参数并获取我的linkedin 个人
我的应用程序从 LinkedIn 获取用户信息,但我找不到从 LinkedIn 获取某人性别的方法。 是否可以? LinkedIn 甚至有性别字段吗? 最佳答案 不。检查这个; https://dev
我很难在 LinkedIn 上获得分享。我正在尝试通过 LinkedIn API V2 发布 LinkedIn 共享,每次我发出发布请求时,我都会收到来自服务器的请求超时(状态 504)答复。这是我的
LinkedIn 的 API 返回以下值: [creationTimestamp] => 1407247548000 它看起来类似于 UNIX 时间戳,但末尾有三个“额外”零。这是什么格式,我该如何解
我正在尝试将从 ugcPosts API 获取组织帖子的现有代码迁移到 Posts API 的新版本调用(版本 202210),但我遇到了获取文章缩略图的问题。我从 Posts API 获得的响应不包
标题几乎说明了一切。有什么方法可以访问 LinkedIn 上大学页面的提要/更新吗? 在他们的开发者网站上唯一提到的大学是他们的 Alumni 小部件。 最佳答案 一句话:没有。 对于 API 的所有
您知道是否可以为 LinkedIn 平台构建应用程序? 最佳答案 是的,他们在 http://developer.linkedin.com/index.jspa 有 API ,允许访问个人资料、连接、
在 LinkedIn 的 API 使用条款 (https://developer.linkedin.com/legal/api-terms-of-use) 的第 2.3 节中,他们提到开发人员最多可以
作为公司页面的管理员,我如何通过 LinkedIn api 访问该公司的帖子 我被要求成为我公司资料的管理员。我创建了一个应用程序并将我的公司映射到该应用程序。但奇怪的是我刚刚获得了该应用程序的三个权
如何为我的网站提取或获取 LinkedIn 推荐?是否有任何插件或 PHP 脚本? 最佳答案 您可以使用 LinkedIn API 提取建议。 ,特别是 Profile API .粗略的步骤是: 创建
我正在为公司建立外部网站,我想展示我们公司的 LinkedIn 个人资料 最近更新 在我们的网站内。目前,当我访问我们公司的 LinkedIn 个人资料时,我可以看到这些最近的更新,这些更新也可供公共
articles API 的 LinkedIn 文档表明我可以通过做一个特定的文章的内容等 GET https://api.linkedin.com/v2/originalArticles/{orig
我想按日期范围获取视频分析。 我关注了视频分析 API, https://learn.microsoft.com/en-us/linkedin/marketing/integrations/commu
我想在我的网站中添加添加个人资料按钮以进行认证,以便用户可以将其添加到他们链接的个人资料中。 为此,我正在使用 任何人都可以帮助这里如何自动归档文件?意味着我想从我的一端发送证书名称、链接、许可证。
当图像通过 LinkedIn API v2 共享到个人资料(而非公司)时,它会显示为好像被裁剪过的一样: 但是,当我在 www.linkedin.com 上上传并分享同一张图片到我的个人资料时,它不显
当图像通过 LinkedIn API v2 共享到个人资料(而非公司)时,它会显示为好像被裁剪过的一样: 但是,当我在 www.linkedin.com 上上传并分享同一张图片到我的个人资料时,它不显
我正在使用 LinkedIn Owin Middleare,今天早上开始遇到问题,现在已将其复制到以下错误: POST https://www.linkedin.com/uas/oauth2/acce
我在我的网站上使用 LinkedIn 分享按钮,我使用相同的脚本将页面分享到 LinkedIn。但是,某些页面是成功的。一些页面失败。这是错误信息 Error while processing rou
有没有一种方法可以使用 LinkedIn API 提取公司洞察信息?我有一个高级帐户,并在 LinkedIn 开发者平台上创建了一个应用程序。我似乎找不到获取公司数据的方法,例如员 worker 数(
我是一名优秀的程序员,十分优秀!