Python Forum
Extract only certain text which are needed
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extract only certain text which are needed
#3
The data is probably coming from a Json and has been now encoded to a Python dictionary.
Then work with dictionary no regex need.
data = {
  "_index": "testdataset",
  "_type": "_doc",
  "_id": "11234567891098646",
  "_score": 1,
  "_source": {
    "_class": "net.local.host.ca",
    "orderNo": "16536668566434698646",
    "orderDt": "20220527",
    "source": 0,
    "mchntId": "0000000002",
    "mchntOrderNo": "01a3f2b53d16290f41f",
    "appid": "0000000003",
    "payChannelId": "payid",
    "amount": 300,
    "clientIp": "192.168.0.1",
    "currency": "0",
    "subject": "",
    "body": "",
    "cpChannel": "google_upi",
    "timeExpire": 1653678578000,
    "description": "",
    "created": 1653657857000,
    "timePaid": 1653657876000,
    "bankType": "",
    "paySt": 2,
    "refundSt": 0,
    "refundedAmt": 0,
    "checkSt": 0,
    "fee": 21,
    "chnlFee": 9,
    "settleSt": 1,
    "rutId": "0000000098",
    "bankRspDesc": "",
    "bankTransactionId": "20220527212419602959728091384475",
    "credential": "214721678116",
    "notifyUrl": "https://localhost/test/site",
    "pageNotifyUrl": "https://localhost/test/site",
    "notifyCnt": 0,
    "notifySt": 0,
    "openId": "",
    "extra": "",
    "countryId": "Brazil",
    "areaId": "",
    "regionId": "brazil",
    "cityId": "toto",
    "countyId": "",
    "modified": 1124657876000,
    "channlInfoId": "b0768be2248a4aee94ac747c2ab0000",
    "email": "[email protected]",
    "mobile": "100000012457",
    "accountOwner": "Tom Hank",
    "merchantParam": "game",
    "transTp": 0,
    "payAccount": "",
    "payType": "",
    "bankCode": "",
    "settleBatchNo": "2022124578950",
    "startRow": 0,
    "pageSize": 0
  }
}
Use.
>>> data['_id']
11234567891098646

>>> data["_source"]["amount"]
300
>>> data["_source"]["countryId"]
Brazil
Reply


Messages In This Thread
RE: Extract only certain text which are needed - by snippsat - Oct-08-2022, 11:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  extract only text strip byte array Pir8Radio 7 3,442 Nov-29-2022, 10:24 PM
Last Post: Pir8Radio
  Extract text rektcol 6 1,954 Jun-28-2022, 08:57 AM
Last Post: Gribouillis
  Extract a string between 2 words from a text file OscarBoots 2 1,996 Nov-02-2021, 08:50 AM
Last Post: ibreeden
  Extract text based on postion and pattern guddu_12 2 1,772 Sep-27-2021, 08:32 PM
Last Post: guddu_12
  Extract specific sentences from text file Bubly 3 3,646 May-31-2021, 06:55 PM
Last Post: Larz60+
  extract color text from PDF Maha 0 2,164 May-31-2021, 04:05 PM
Last Post: Maha
Question How to extract multiple text from a string? chatguy 2 2,548 Feb-28-2021, 07:39 AM
Last Post: bowlofred
  How to extract a single word from a text file buttercup 7 3,965 Jul-22-2020, 04:45 AM
Last Post: bowlofred
  How to extract specific rows and columns from a text file with Python Farhan 0 3,513 Mar-25-2020, 09:18 PM
Last Post: Farhan
  Extract Strings From Text File - Out Put Results to Individual Files dj99 8 5,181 Jun-28-2018, 10:41 AM
Last Post: dj99

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020