Rest 引用转储的LinkedIn API数据
这里有一个我不知道怎么解决的小问题,我想你们可以告诉我该怎么走。我已经成功地使用LinkedIn REST API(XML和JSON)提取了所有连接数据,并将它们转储(前者使用cPickle插件)。问题是我需要引用数据中的单个字段,因此决定使用XML,因为它似乎是迄今为止最容易使用的。当我引用.pickle文件中的特定字段时,会出现以下错误:Rest 引用转储的LinkedIn API数据,rest,python-2.7,linkedin,pickle,Rest,Python 2.7,Linkedin,Pickle,这里有一个我不知道怎么解决的小问题,我想你们可以告诉我该怎么走。我已经成功地使用LinkedIn REST API(XML和JSON)提取了所有连接数据,并将它们转储(前者使用cPickle插件)。问题是我需要引用数据中的单个字段,因此决定使用XML,因为它似乎是迄今为止最容易使用的。当我引用.pickle文件中的特定字段时,会出现以下错误: AttributeError: 'str' object has no attribute 'location' 但是,使用记事本打开pickle文件时
AttributeError: 'str' object has no attribute 'location'
但是,使用记事本打开pickle文件时,我可以看到所有连接的位置字段都以XML格式存储。真奇怪
这是我的推荐代码:
import cPickle
connections_data = 'linkedin_connections.pickle'
response = cPickle.load(open(connections_data))
print response
locations = [ec.location for ec in response]
我设置了一个print函数来显示文件中的内容,所有数据都使用restapi的people调用显示为正常的XML输出。XML数据如下所示:
<person>
<id>ID_number</id>
<first-name>blah</first-name>
<last-name>blah</last-name>
<headline>Business Development and Sales Executive at Computaris</headline>
<picture-url>picture_url</picture-url>
<api-standard-profile-request>
<url>profile_request</url>
<headers total="1">
<http-header>
<name>x-li-auth-token</name>
<value>name</value>
</http-header>
</headers>
</api-standard-profile-request>
<site-standard-profile-request>
<url>request_url</url>
</site-standard-profile-request>
<location>
<name>location</name>
<country>
<code>country_code</code>
</country>
</location>
<industry>industry</industry>
任何帮助都将不胜感激