Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing json data with newline characters in python

I want to parse following JSON with IPs and its counts into a single list containing only IPs using Python.

& code: `

response_ips= requests.get(url=link_getResults,headers=payload)
response_ips.raise_for_status()

data_ips= json.loads(response_ips.text)
results=data_ips['results']
print results
like image 282
Ashwin Avatar asked Mar 13 '26 20:03

Ashwin


1 Answers

Split the results on \r\n to get each line, then split each of those on \t to separate the IP from the count.

ips = [line.split("\t")[0] for line in results.split("\r\n")]
print(ips)
like image 113
Barmar Avatar answered Mar 16 '26 10:03

Barmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!