简体   繁体   English

如何调用 Rest API 并使用该 API 中的数据?

[英]How to call Rest API and use the data in that API?

I have a scenario where I will open my website and than I have to call the Rest API where in that API I will be needing some data, like user name,password and some URLs.我有一个场景,我将打开我的网站,然后我必须调用 Rest API,在该 API 中,我将需要一些数据,例如用户名、密码和一些 URL。 The purpose of calling API is that I dont know the credentials as well as the URLS which is going to get check and every time these data will get change therefore I will just call an API.调用 API 的目的是我不知道凭证以及要检查的 URLS,每次这些数据都会发生变化时,我只会调用 API。 Below is my Selenium Python下面是我的硒 Python

from selenium import webdriver
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# declare variable to store the URL to be visited
base_url="https://www.fitotouch.com/qitouch"

driver = webdriver.Chrome('E:/Chrome driver/chromedriver.exe')
driver.maximize_window()
#function of our 'driver' object.
driver.implicitly_wait(10) #10 is in seconds
driver.get(base_url)
driver.implicitly_wait(10)
driver.find_element_by_name('password').send_keys("*****")
driver.implicitly_wait(10)
driver.find_element_by_class_name('arrow-icon').click()

After above click command I have to call API and Login from the data given in the API.在上面的单击命令之后,我必须从 API 中给出的数据中调用 API 和登录。

My API is : http://110.93.230.117:1403/api/order/5e439b7052fcf2189ccb5207我的 API 是: http : //110.93.230.117 : 1403/ api/ order/5e439b7052fcf2189ccb5207

If I can get solution in Java than also it is Fine.如果我能用 Java 得到解决方案,那也很好。

在此处输入图片说明

Use requests module to get the data as dictionary, from there you can get the values by the key使用requests模块将数据作为字典获取,从那里你可以通过键获取值

import requests

data = requests.get('http://110.93.230.117:1403/api/order/5e439b7052fcf2189ccb5207').json()
print(data)

"""
{'date': '2020-02-12T06:30:08.106Z',
 '_id': '5e439b7052fcf2189ccb5207',
 'fitoName': 'Chinasor 01 - Bu Yang Huan Wu Wan',
 'fitoCode': 'Chinasor 01',
 'providerName': 'Soria - Chinasor',
 'providerCode': 'Chinasor 01',
 'valueItem': '01',
 'Email': 'helder@gmail.com',
 '__v': 0}
"""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM