我有以下字符串,
s = {$deletedFields:name:[standardizedSkillUrn,standardizedSkill],entityUrn:urn:li:fs_skill:(ACoAAA0C3rkBDZ7qyoWoEmj9CxUv3QW6brC836w,25),name:Political Campaigns,$type:com.linkedin.voyager.identity.profile.Skill},{$deletedFields:[standardizedSkillUrn,standardizedSkill],entityUrn:urn:li:fs_skill:(ACoAAA0C3rkBDZ7qyoWoEmj9CxUv3QW6brC836w,28),name:Politics,$type:com.linkedin.voyager.identity.profile.Skill},name:
{$deletedFields:[standardizedSkillUrn,standardizedSkill],entityUrn:urn:li:fs_skill:(ACoAAA0C3rkBDZ7qyoWoEmj9CxUv3QW6brC836w,27),name:Political Consulting,$type:com.linkedin.voyager.identity.profile.Skill},
{$deletedFields:[standardizedSkillUrn,standardizedSkill],entityUrn:urn:li:fs_skill:(ACoAAA0C3rkBDZ7qyoWoEmj9CxUv3QW6brC836w,26),name:Grassroots Organizing,$type:com.linkedin.voyager.identity.profile.Skill},
{$deletedFields:[],profileId:ACoAAA0C3rkBDZ7qyoWoEmj9CxUv3QW6brC836w,elements:[urn:li:fs_skill:(ACoAAA0C3rkBDZ7qyoWoEmj9CxUv3QW6brC836w,25),urn:li:fs_skill:(ACoAAA0C3rkBDZ7qyoWoEmj9CxUv3QW6brC836w,26),urn:li:fs_skill:(ACoAAA0C3rkBDZ7qyoWoEmj9CxUv3QW6brC836w,27),urn:li:fs_skill:(ACoAAA0C3rkBDZ7qyoWoEmj9CxUv3QW6brC836w,28)],paging:urn:li:fs_profileView:ACoAAA0C3rkBDZ7qyoWoEmj9CxUv3QW6brC836w,skillView,paging,$type:com.linkedin.voyager.identity.profile.SkillView,$id:urn:li:fs_profileView:ACoAAA0C3rkBDZ7qyoWoEmj9CxUv3QW6brC836w,skillView},
{$deletedFields:[]
我想抓住
name:Political Campaigns
name:Politics
name:Political Consulting
name:Grassroots Organizing
name = [Political Campaigns , Politics, Political Consulting, Grassroots Organizing]
以上字符串来自我想废弃的文件。
请记住name
文件中有很多实例,
有没有办法获取fs_skill
然后一些垃圾值,然后在它附近寻找name:
并抓住该字符串结束于。
答案 0 :(得分:1)
data = [pair[5:] for pair in s.split(',') if pair[:4] == 'name' and pair[5].isalpha()]
输出:
['Political Campaigns', 'Politics', 'Political Consulting', 'Grassroots Organizing']
你可以尝试上面的代码片段,希望这有帮助吗