编程和python新手!
我正在使用sdk以编程方式搜索联系人目录(rocketreach)。问题在这里:
import rocketreach
rr = rocketreach.Gateway(api_key='5f522ek578e02c8b3eace69a805bc1249218454')
lookup = rr.person.lookup(extras={'name': 'Marc Benioff', 'current_employer': 'Salesforce'})
if lookup.is_success:
print(repr(lookup.person))
返回一个字典:
{'current_employer': 'Salesforce',
'current_personal_email': 'benioff@gmail.com',
'current_title': 'Chairman and Co-CEO',
'current_work_email': 'marcb@salesforce.com',
'emails': [{'email': 'm.benioff@salesforce.com',
'smtp_valid': 'valid',
'type': 'professional'},
{'email': 'mbenioff@salesforce.com',
'smtp_valid': 'valid',
'type': 'professional'}],
'id': 5244,
'linkedin_url': 'https://www.linkedin.com/in/marcbenioff',
'links': {'aboutme': 'http://www.about.me/marcbenioff',
'amazon': 'http://www.amazon.com/gp/pdp/profile/AZGYQG724J6ON//190-5748375-2756131',
'angel': 'https://angel.co/benioff',
'angellist': 'http://www.angel.co/benioff',
'crunchbase': 'https://www.crunchbase.com/person/marc-benioff'},
'location': 'San Francisco, California, United States',
'name': 'Marc Benioff',
'phones': [],
'profile_pic': 'https://d1hbpr09pwz0sk.cloudfront.net/profile_pic/marc-benioff-4492e698',
'status': 'complete'}
但是当我尝试使用。get检索'email '键下的值时,我得到一个错误:
example = repr(lookup_result.person)
example.get('emails')
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
example.get('emails')
AttributeError: 'str' object has no attribute 'get'
我不明白为什么....非常感谢你的帮助:)谢谢!
在问题中包含的example
中有给定对象的可打印表示形式,即lookup_result.person
。
你可以阅读更多关于repr
您必须访问实际对象。您可以这样修改:
example = lookup_result.person
emails_list = example.get('emails')
print(emails_list)
输出将像这样:
[
{
"email": "m.benioff@salesforce.com",
"smtp_valid": "valid",
"type": "professional",
},
{"email": "mbenioff@salesforce.com", "smtp_valid": "valid", "type": "professional"},
]