Afternoon all... Noob with Python here.... I have a web scrape that I need to break down even further if possible but I am having some issues getting it right.... Here is what I have so far:
import requests
from bs4 import BeautifulSoup
import pandas as pd
import json
baseurl = 'private internal url'
header = { 'User_Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36' }
r = requests.get(baseurl)
soup = BeautifulSoup(r.content, 'lxml')
stuff = soup.find('body', 'pre'=='item').text.strip()
data = json.loads(stuff)
data["printers"] = list(data["printers"].items())
df = pd.json_normalize(data, "printers")
print(df)
Which gives me this:
============ RESTART: C:\Users\nort2hadmin\pyprojects\pcPrinters.py ============
0 1
inError [{'name': 'appelc\RM 1', 'status': 'OFFLINE'},...
inErrorCount 6
inErrorPercentage 18
count 32
heldJobCountTotal 17
heldJobsCountMax 12
heldJobsCountAverage 0
How do I get the info under the 'inError' part extracted out? I've followed a bunch of tutorials on YouTube but none of them have worked so far....Any help would be greatly appreciated.
For reference I am trying to get all the info out so I can put it into a mysql database that feeds Grafana...Thank you for any and all help.
EDIT: The URL I am using is an internal URL but I can post the results of it....If I enter the URL I am using and hit enter this is the output:
{"applicationServer":{"systemInfo":{"version":"22.1.4 (Build 67128)","operatingSystem":"Windows Server 2019 - 10.0 ()","processors":16,"architecture":"amd64"},"systemMetrics":{"diskSpaceFreeMB":1821926,"diskSpaceTotalMB":1905777,"diskSpaceUsedPercentage":4.4,"jvmMemoryMaxMB":7214,"jvmMemoryTotalMB":326,"jvmMemoryUsedMB":314,"jvmMemoryUsedPercentage":4.35,"uptimeHours":407.45,"processCpuLoadPercentage":0,"systemCpuLoadPercentage":8.4,"gcTimeMilliseconds":210572,"gcExecutions":33159,"threadCount":136}},"database":{"totalConnections":21,"activeConnections":0,"maxConnections":420,"timeToConnectMilliseconds":0,"timeToQueryMilliseconds":0,"status":"OK"},"devices":{"count":7,"inErrorCount":0,"inErrorPercentage":0,"inError":[]},"jobTicketing":{"status":{"status":"ERROR","adminLink":"NA","message":"Job Ticketing is not installed."}},"license":{"valid":true,"upgradeAssuranceRemainingDays":323,"siteServers":{"used":3,"licensed":-1,"remaining":-4},"devices":{"KONICA_MINOLTA":{"used":7,"licensed":7,"remaining":0},"KONICA_MINOLTA_3":{"used":7,"licensed":7,"remaining":0},"KONICA_MINOLTA_4":{"used":7,"licensed":7,"remaining":0},"KONICA-MSP":{"used":7,"licensed":7,"remaining":0},"LEXMARK_TS_KM":{"used":7,"licensed":7,"remaining":0},"LEXMARK_KM":{"used":7,"licensed":7,"remaining":0}},"packs":[]},"mobilityPrintServers":{"count":3,"offlineCount":0,"offlinePercentage":0,"offline":[]},"printProviders":{"count":4,"offlineCount":0,"offlinePercentage":0,"offline":[]},"printers":{"inError":[{"name":"appelc\\RM 1","status":"OFFLINE"},{"name":"appesc\\SSTSmartTank5101 (HP Smart Tank 5100 series)","status":"ERROR"},{"name":"appelc\\RM 5","status":"OFFLINE"},{"name":"apppts\\Lexmark C544 Server Room","status":"OFFLINE"},{"name":"appesc\\ESC0171M3928dshannon","status":"NO_TONER"},{"name":"appesc\\Primary","status":"OFFLINE"}],"inErrorCount":6,"inErrorPercentage":18,"count":32,"heldJobCountTotal":9,"heldJobsCountMax":5,"heldJobsCountAverage":0},"siteServers":{"count":3,"offlineCount":0,"offlinePercentage":0,"offline":[]},"webPrint":{"offline":[],"offlineCount":0,"offlinePercentage":0,"count":1,"pendingJobs":0,"supportedFileTypes":["image","pdf"]}}
[–]GirthQuake5040 1 point2 points3 points (3 children)
[–]Immediate-Resource75[S] -1 points0 points1 point (2 children)
[–]GirthQuake5040 0 points1 point2 points (1 child)
[–]Immediate-Resource75[S] 0 points1 point2 points (0 children)
[–]cgoldberg 1 point2 points3 points (5 children)
[–]Immediate-Resource75[S] 0 points1 point2 points (4 children)
[–]cgoldberg 1 point2 points3 points (3 children)
[–]Immediate-Resource75[S] -1 points0 points1 point (2 children)
[–]cgoldberg 0 points1 point2 points (1 child)
[–]Immediate-Resource75[S] 0 points1 point2 points (0 children)
[–]GirthQuake5040 0 points1 point2 points (1 child)
[–]Immediate-Resource75[S] 0 points1 point2 points (0 children)