我是编程的初学者,我正在尝试使用API使我的工作自动化。
我得到的响应很好,但是我只对两个值感兴趣,即主机和端口。
这是我的代码的一部分
import requests
url = "https://proxy6.net/api/xxx"
def descr():
return 88
querystring = {"descr":descr()}
headers = {
'Cache-Control': "no-cache",
'Postman-Token': "xxx"
}
response = requests.request("GET", url, headers=headers, params=querystring)
print(response.text)
如何仅打印主机和端口值?
非常感谢
答案 0 :(得分:0)
Public Sub uspLoad(ByVal DateFrom As Date, ByVal DateTo As Date)
ds.Tables.Add("tbComparison")
ds.Tables("tbComparison").Columns.Add("PlannedDescription", GetType(String))
ds.Tables("tbComparison").Columns.Add("Planned", GetType(Decimal))
ds.Tables("tbComparison").Columns.Add("Actual", GetType(Decimal))
Dim connectionString As String = My.Settings.ConnString
Dim sql As String =
"Select b.PlannedDescription,
(SELECT SUM(c.PlannedAmount) FROM DT_PLANNED_TRANSACTION c
WHERE(c.PlannedDate)>=#" & Format(DateFrom, "yyyy/MM/dd") & "# And (c.PlannedDate)<=#" & Format(DateTo, "yyyy/MM/dd") & "#
And c.PlannedDescription = b.PlannedDescription
And (c.PlannedType)='P'
) AS [Planned],
(SELECT SUM(a.PlannedAmount) FROM DT_PLANNED_TRANSACTION A
WHERE(a.PlannedDate)>=#" & Format(DateFrom, "yyyy/MM/dd") & "# And (a.PlannedDate)<=#" & Format(DateTo, "yyyy/MM/dd") & "#
And a.PlannedDescription = b.PlannedDescription
And (a.PlannedType)='A'
) AS [Actual]
From DT_PLANNED_TRANSACTION As b
Where ((b.PlannedType) ='A' AND (b.PlannedDate)>=#" & Format(DateFrom, "yyyy/MM/dd") & "# And (b.PlannedDate)<=#" & Format(DateTo, "yyyy/MM/dd") & "#)
GROUP BY b.PlannedDescription"
Dim connection As New OleDbConnection(connectionString)
Dim dataadapter As New OleDbDataAdapter(sql, connection)
connection.Open()
dataadapter.Fill(ds, "tbComparison")
connection.Close()
DataGridView1.DataSource = ds.Tables("tbComparison")
答案 1 :(得分:0)
import requests
import json
url = "https://proxy6.net/api/xxx"
def descr():
return 88
querystring = {"descr":descr()}
headers = {
'Cache-Control': "no-cache",
'Postman-Token': "xxx"
}
response = requests.request("GET", url, headers=headers, params=querystring)
response = response.json()
print(response['list']['xx']['host'])
print(response['list']['xx']['port'])
说明:
{"status":"yes","user_id":"xx","balance":"xx","currency":"xx","list_count":1,"list":{"xx":{"id":"xx","version":"x,"ip":"xx","host":"xx","port":xx","user":"xx","pass":"xx","type":"socks","country":"us","date":"2018-09-05 22:00:22","date_end":"2018-10-05 22:00:22","unixtime":1536174022,"unixtime_end":1538766022,"descr":"88","active":"1"}}}
response['list'] gives `{"xx":{"id":"xx","version":"x,"ip":"xx","host":"xx","port":xx","user":"xx","pass":"xx","type":"socks","country":"us","date":"2018-09-05 22:00:22","date_end":"2018-10-05 22:00:22","unixtime":1536174022,"unixtime_end":1538766022,"descr":"88","active":"1"}}`
response['list']['xx'] gives `{"id":"xx","version":"x,"ip":"xx","host":"xx","port":xx","user":"xx","pass":"xx","type":"socks","country":"us","date":"2018-09-05 22:00:22","date_end":"2018-10-05 22:00:22","unixtime":1536174022,"unixtime_end":1538766022,"descr":"88","active":"1"}`
response['list']['xx']['host'] gives host key value
response['list']['xx']['port'] gives port key value
如果您有疑问,请告诉我