当前位置:网站首页>项目Demo
项目Demo
2022-06-24 06:32:00 【_程序媛_】
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>json模拟数据</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.container {
width: 800px;
margin: 200px auto;
padding: 30px 0;
border: 1px dashed #272627;
}
.test {
width: 100%;
padding: 10px 0;
margin: 20px 0;
color: #4bade8;
font-size: 18px;
text-align: center;
}
#jsonList {
width: 500px;
margin: 0 auto;
}
#jsonTable th,
td {
padding: 6px 0;
line-height: 30px;
text-align: center;
}
</style>
</head>
<body>
<div class="container">
查询:<input id="shoppname">
<button onclick="getAir()">开始</button>
<div class="test">城市信息数据</div>
<table border="1" cellspacing="0" bordercolor="#4bade8" cellpadding="0" id="jsonList">
<tr>
<th>商品图片</th>
<th>标题</th>
<th>销量</th>
<th>价格</th>
</tr>
</table>
</div>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
});
function getAir() {
var temp = '';
var shoppname = $("#shoppname")
$.ajax({
type: "get",
url: "http://127.0.0.1:8888/login?name="+shoppname.val(),
crossDomain:true,
withCredentials: true,
dataType: "json",
success: function(res) {
var list = res.air;
console.log(list);
for(var $i = 0; $i < list.length; $i++) {
temp +=
'<tr>' +
'<td><img src=https://img10.360buyimg.com/n7/'+ list[$i].image_url+'></td>'+
'<td>' + list[$i].ad_title + '</td>' +
'<td>' + list[$i].ad_title + '</td>' +
'<td>' + list[$i].fuzzy_comment_num + '</td>' +
'<td>' + list[$i].pc_price + '</td>' +
'</tr>';
}
$("#jsonList tr:not(:first)").html("");
$("#jsonList").append(temp);
}
});
}
</script>
</body>
</html>
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
import requests
import flask, json
from flask import request
from functools import wraps
from flask import make_response
# 创建一个服务,把当前这个python文件当做一个服务
from flask_cors import *
server = flask.Flask(__name__)
CORS(server, supports_credentials=True)
headers = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36', 'Cookie': 'shshshfpa=5719f356-617a-a963-c125-b68ffb376a27-1655426903; shshshfpb=mc6Ix2qAeARfFCYp97pfRgg; __jdu=522058129; areaId=20; ipLoc-djd=20-1715-0-0; unpl=JF8EAKtnNSttW0wHDB0EGBsVQ14DW19dHB8AZ2AMBg5QTFQGTFUcFxd7XlVdXhRKEB9vYRRVVVNIUQ4bCysSEXteXVdZDEsWC2tXVgQFDQ8VXURJQlZAFDNVCV9dSRZRZjJWBFtdT1xWSAYYRRMfDlAKDlhCR1FpMjVkXlh7VAQrBhgREU9UVF1VOHsQM19XAlxUUUpkBCsDK1BEF15XWFsOBhMAbGYBXV1bQ2QEKwE; __jdv=76161171|baidu-pinzhuan|t_288551095_baidupinzhuan|cpc|0f3d30c8dba7459bb52f2eb5eba8ac7d_0_26b87728492f43df92968cb9612ff646|1655428913944; __jda=122270672.522058129.1655426897.1655426914.1655428914.2; __jdc=122270672; shshshfp=5daf55a5f6651ee4daeaeb350d688ac1; _gia_s_local_fingerprint=694e91f20a9c0034add669b38a1635be; mba_muid=522058129; wlfstk_smdl=9mxgmgoabz90ko50ikngzjv2ijvmiyds; ip_cityCode=1715; 3AB9D23F7A4B3C9B=WC647EA3LN4QKED7CK6UDPBV52MLI4PNMGDKRIHXZPKU3FBSIXYEEBOMEYKNWT2GWONSSZJ4PVXXXSXYNB5WC6DXPQ', } # server.route()可以将普通函数转变为服务 登录接口的路径、请求方式 @server.route('/login', methods=['get', 'post']) def login(): # 获取通过url请求传参的数据 username = request.values.get('name') print(username+"传传传传传") url = 'https://search-x.jd.com/Search?callback=jQuery3783932&area=50&enc=utf-8&keyword=+' + username + '+&adType=7&page=1&ad_ids=291%3A33&xtest=new_search&_=1655429655358' resp = requests.get(url, headers=headers) respjson = resp.text.split("jQuery3783932(")[1] respjson1 = respjson[0:len(respjson) - 1] print(respjson1) test = json.loads(respjson1.replace('291', 'air', 1)) # json_data = resp.json(test) resu = test return json.dumps(resu, ensure_ascii=False) # 将字典转换为json串, json是字符串 # # https://cd.jd.com/description/channel?skuId=10025631728908&mainSkuId=100029662616&charset=utf-8&cdn=2&callback=showdesc def allow_cross_domain(fun): @wraps(fun) def wrapper_fun(*args, **kwargs): rst = make_response(fun(*args, **kwargs)) rst.headers['Access-Control-Allow-Origin'] = '*' rst.headers['Access-Control-Allow-Methods'] = 'PUT,GET,POST,DELETE' allow_headers = "Referer,Accept,Origin,User-Agent" rst.headers['Access-Control-Allow-Headers'] = allow_headers return rst return wrapper_fun if __name__ == '__main__': server.run(debug=True, port=8888, host='0.0.0.0') # 指定端口,host,0.0.0.0代表不管几个网卡,任何ip都可访问 边栏推荐
- 10 year old drivers who have been engaged in software testing tell you what type of software is suitable for automation
- How accurate are the two common methods of domain name IP query
- Comparison of common layout solutions (media query, percentage, REM and vw/vh)
- Architecture: rest and HATEOAS
- The 2021 Tencent digital ecology conference landed in Wuhan, waiting for you to come to the special session of wechat with low code
- WordPress pill applet build applet from zero to one [pagoda panel environment installation]
- Enter the software test pit!!! Software testing tools commonly used by software testers software recommendations
- Spirit information development log (1)
- Correct way to update Fedora image Yum source to Tencent cloud Yum source
- Royal treasure: an analysis of SQL algebra optimization
猜你喜欢

Technology is a double-edged sword, which needs to be well kept

Enter the software test pit!!! Software testing tools commonly used by software testers software recommendations
Fault analysis | using --force to batch import data leads to partial data loss

基于三维GIS系统的智慧水库管理应用

创客教育给教师发展带来的挑战

Manual for automatic testing and learning of anti stepping pits, one for each tester

A cigarette of time to talk with you about how novices transform from functional testing to advanced automated testing

解读AI机器人产业发展的顶层设计

【二叉数学习】—— 树的介绍

ServiceStack. Source code analysis of redis (connection and connection pool)
随机推荐
Deploy DNS server using dnsmasq
From home to Ali, a year for junior students to apply for jobs
What transmission modes does the IOT data gateway support
Could not read username for xxxxx
How to build a website after having a domain name? Can you ask others to help register the domain name
Analysis of official template of wechat personnel recruitment management system (I)
Free and easy-to-use screen recording and video cutting tool sharing
Come on, it's not easy for big factories to do projects!
Easy car Interviewer: talk about MySQL memory structure, index, cluster and underlying principle!
The new version of Tencent Youtu ncnn is suitable for domestic CPUs, and the maximum speed is increased by 70 times
Tencent launched the "reassuring agricultural product plan" to support 100 landmark agricultural product brands!
[fault announcement] one stored procedure brings down the entire database
【二叉数学习】—— 树的介绍
WordPress pill applet build applet from zero to one [pagoda panel installation configuration]
Interpreting the new features of Appstore: Customizing product pages and a/b test tools
How to solve the problem that after Tencent cloud sets static DNS, restarting the machine becomes dynamic DNS acquisition
The difference between ArrayList and LinkedList and the principle of using scene locality
Just now, we received a letter of thanks from Bohai University.
Micro build low code supports Excel to import data source
Multi objective Optimization Practice Based on esmm model -- shopping mall