当前位置:网站首页>项目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都可访问 边栏推荐
- Operation and maintenance dry goods | how to improve the business stability and continuity through fault recovery?
- What are the categories of edge computing devices
- A cigarette of time to talk with you about how novices transform from functional testing to advanced automated testing
- Authoritative recognition! Tencent cloud data security Zhongtai was selected as the 2021 pioneer practice case
- Talk about the story behind search engines
- What is a secondary domain name primary domain name how to apply for a secondary domain name
- Koa source code analysis
- Tencent security release data security compliance capability map
- Analysis of official template of wechat personnel recruitment management system (II)
- Why the computer can't start
猜你喜欢

ServiceStack. Source code analysis of redis (connection and connection pool)

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

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

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

The product layout is strengthened, the transformation of digital intelligence is accelerated, and FAW Toyota has hit 2022million annual sales

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

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

【二叉树】——二叉树中序遍历
![[fault announcement] one stored procedure brings down the entire database](/img/7c/e5adda73a077fe4b8f04b59d1e0e1e.jpg)
[fault announcement] one stored procedure brings down the entire database

Enter the software test pit!!! Software testing tools commonly used by software testers software recommendations
随机推荐
What is the domain name query network and how it should be used
Easyrtc call error `failed to execute'send'on'rtcdatachannel'
Spirit information development log (3)
Apache enables gzip compressed web page transmission method
Web automated testing (2): choose selenium advantage? Comparison with phantomjs/qtp/monkey
Distributed cache breakdown
ServiceStack. Source code analysis of redis (connection and connection pool)
Web automation test (3): Selenium basic course of web function automation test
Quick reference table of PHP security configuration maintained by OWASP
Analysis of official template of wechat personnel recruitment management system (I)
Feign request return value inverse sequence localdatetime exception record
Differences between JSON objects and JSON strings
Talk about how to dynamically specify feign call service name according to the environment
How to recover data by splicing database fragments
How to build a website after having a domain name? Can you ask others to help register the domain name
SQL server memory management on cloud
At the beginning of the school season, use this template to improve the management level
Tencent security apkpecker launched dex-vmp automatic shelling service
Attack and defense enlightenment: chromium component risk analysis and convergence
Printer connection mode