如何从这些字符串中提取数据?

时间:2021-07-16 22:16:15

标签: python web-scraping

我正在制作一个程序,该程序包括从作业页面抓取数据,然后获取这些数据

{"job":{"ciphertext":"~01142b81f148312a7c","rid":225177647,"uid":"1416152499115024384","type":2,"access":4,"title":"Need app developers to handle our app upgrades","status":1,"category":{"name":"Mobile Development","urlSlug":"mobile-development"
,"contractorTier":2,"description":"We have an app currently built, we are looking for someone to \n\n1) Manage the app for bugs etc \n2) Provide feature upgrades \n3) Overall Management and optimization \n\nPlease get in touch and i will share more details. ","questions":null,"qualifications":{"type":0,"location":null,"minOdeskHours":0,"groupRecno":0,"shouldHavePortfolio":false,"tests":null,"minHoursWeek":40,"group":null,"prefEnglishSkill":0,"minJobSuccessScore":0,"risingTalent":true,"locationCheckRequired":false,"countries":null,"regions":null,"states":null,"timezones":null,"localMarket":false,"onSiteType":null,"locations":null,"localDescription":null,"localFlexibilityDescription":null,"earnings":null,"languages":null
],"clientActivity":{"lastBuyerActivity":null,"totalApplicants":0,"totalHired":0,"totalInvitedToInterview":0,"unansweredInvites":0,"invitationsSent":0
,"buyer":{"isPaymentMethodVerified":false,"location":{"offsetFromUtcMillis":14400000,"countryTimezone":"United Arab Emirates (UTC+04:00)","city":"Dubai","country":"United Arab Emirates"
,"stats":{"totalAssignments":31,"activeAssignmentsCount":3,"feedbackCount":27,"score":4.9258937139,"totalJobsWithHires":30,"hoursCount":7.16666667,"totalCharges":{"currencyCode":"USD","amount":19695.83
,"jobs":{"postedCount":59,"openCount":2
,"avgHourlyJobsRate":{"amount":19.999534874418824

但问题是我需要的唯一数据是: -标题 -描述 - 客户活动(lastBuyerActivity、totalApplicants、totalHired、totalInvitedToInterview、unansweredInvites、invitationsSent) - 买方(isPaymentMethodVerified,位置(国家)) -stats(所有项目) - 工作(所有项目) -avgHourlyJobsRate

3 个答案:

答案 0 :(得分:0)

使用 json.loads 将数据转换为字典

然后您可以轻松地使用您想要查找或过滤数据的字典键。

答案 1 :(得分:0)

这似乎是一本字典,因此您可以通过执行以下操作从中提取某些内容:例如:dictionary["job"]["uid"]。如果是 Json 文件,则将数据转换为 Python 字典

答案 2 :(得分:0)

这类数据是 JSON 类型的数据。 Python 通过dictionary 数据类型来理解这些类型的数据。
假设您将数据存储在字符串中。您可以使用 di = exec(myData) 将字符串转换为字典。然后您可以访问结构化数据,例如:di["job"],它返回数据的 job 部分。

di = exec(myData)
print(`di["job"]`)

然而,这只是一个 hack,不推荐,因为它是一个 有点凌乱和非pythonic
合适的方法是使用 JSON 库将数据转换为字典。看看下面的代码片段,了解什么是合适的方法:

import json

myData = "Put your data Here"
res = json.loads(myData)
print(res["jobs"])
相关问题