[Python] 纯文本查看 复制代码import requests
import re
import json
import parsel
import execjs
#价格接口:#url = "https://pas.suning.com/nspcsale_0_000000012391487471_000000012391487471_0070517287_100_523_5230199_20089_1000184_9184_11464_Z001___R1901001_1.0_1___000060021____0___100.0_2__20002_20006___.html"
#评价接口: "https://review.suning.com/ajax/review_count/cluster-38047633-000000012391487471-0070517287-----satisfy.htm"
def get_response(url):
headers = {
"Accept": "*/*",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,ru;q=0.7",
"Connection": "keep-alive",
"Referer": "https://product.suning.com/",
"Sec-Fetch-Dest": "script",
"Sec-Fetch-Mode": "no-cors",
"Sec-Fetch-Site": "same-site",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
"sec-ch-ua": "\"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"108\", \"Google Chrome\";v=\"108\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\""
}
cookies = {
"_snmc": "1",
"_snsr": "baidu.com%7Corganic%7C%7C%7C*%3A*",
"_snvd": "1698328986656leJN4UjrvpN",
"tradeMA": "133",
"authId": "sidSLM3DJDUvAh4GUxLLo9vaNTsPW2xkpC",
"secureToken": "616839E1001DB234782984DC585F73FA",
"ssotbrd": "TGTaJpC10FykxDtsO7TjtBkRkG214tTfbAfKHggDsZF",
"streetCode": "5230199",
"cityCode": "523",
"districtId": "11464",
"cityId": "9184",
"_snzwt": "THbNI018b6c4cdb21TjNQc100",
"totalProdQty": "0",
"hm_guid": "1f7b3b82-f0ae-49e5-9c4b-4a9b11f82074",
"_df_ud": "31de0918-090a-4823-b8a7-702a810d9879",
"SN_CITY": "100_523_1000184_9184_01_11464_1_1_99_5230199",
"route": "d54699ac239816bd68ff83ef1b65fba2",
"ariaDefaultTheme": "null",
"_snms": "169833066286778211",
"smhst": "12391487471|0070517287a12391486993|0070517287",
"token": "296395f6-0d90-4a41-8cb9-62eba4af059d",
"_snma": "1%7C169832898479926963%7C1698328984799%7C1698330661818%7C1698330671692%7C8%7C1",
"_snmp": "169833067062430434",
"_snmb": "169832898605510108%7C1698330671767%7C1698330671721%7C8"
}
response = requests.get(url, headers=headers, cookies=cookies)
return response
def get_content(response,flag=0):
#flag:如果传入0,False,传入1,获取源码,
text=response.text
if flag:
json_str=re.findall('\((.*?)\)',text)[0]
return json.loads(json_str)
return text
def parse_html(html_data,url):
#解析源代码
select=parsel.Selector(html_data)
title=re.findall('"itemDisplayName":"(.*?)"',html_data)[0]
is_zy=select.xpath('//*[@id="itemNameZy"]/li/text()').get("非自营")
brand=select.xpath('string(//div[@class="breadcrumb"]/div[3]/span)').get()
good_type=select.xpath('string(//div[@class="breadcrumb"]/div[2]/span)').get()
shop_name=select.xpath('string(//a[@class="header-shop-name"])').get()
content=select.xpath('string(//div[@class="tabarea-content not-anchor clearfix"])').get()
img = select.xpath('//*[@id="bigImg"]/img/@src').get()
return [title,is_zy,brand,good_type,shop_name,content,img]
def main(url):
response=get_response(url)
main_html=get_content(response)
info_list=parse_html(main_html,url)
js_code=re.findall('',main_html)[0]
print(js_code)
f=open("苏宁易购.js",mode='r',encoding='utf-8').read()
f=f.replace("jscode",js_code)
ctx=execjs.compile(f)
print(ctx)
price_url=ctx.call("sdk")
print(price_url)
#print(main_html)
main("https://product.suning.com/0000000000/12389328851.html")
[JavaScript] 纯文本查看 复制代码window = global
window.screen = {
width: 1536
}
location = {
hostname: 'product.suning.com'
}
document = {
location: location
};
location.hostname = 'product.suning.com'
var sn = sn || {
"listHost": "//list.suning.com/",
"conline": "conline.suning.com",
"ninePartNumber": "12389328846",
"serviceCentre": "",
"zoneDomain": "//zone.suning.com",
"prdType": "g",
"prdTypeVal": "textContent",
"virtualPartNumber": "000000000945156942",
"cartPath": "cart.suning.com/emall",
"cartHost": "cart.suning.com",
"now": "2023-11-12 19:53:21",
"onlineDomain": "online.suning.com",
"vcsDomain": "//vcs.suning.com",
"subcodeflag": "1",
"sizeAttr": "2",
"productId": "0",
"itemId": "0",
"yushouDomain": "//yushou.suning.com",
"brandFlag": "",
"imageDomianDir": "//image3.suning.cn",
"qiangDomain": "qiang.suning.com",
"spikeHost": "promotion.suning.com",
"itemDomain": "//item.suning.com",
"shopMainPh": ".suning.com",
"shopPath": "//shop",
"tuijianDomain": "//tuijian.suning.com",
"scriptDomain": "//script.suning.cn",
"elecProductDomain": "//product.suning.com",
"itemDisplayName": "Apple iPhone 14 128G 星光色 移动联通电信5G 双卡双待手机",
"categoryName3": "手机",
"brandDomain": "//brand.suning.com",
"domain": "www.suning.com",
"shopType": "0",
"vendorCode": "0000000000",
"catenIds": "R1901001",
"catalogId": "10051",
"commonResourceURL": "//image.suning.cn",
"category1": "20089",
"categoryName1": "手机/数码/配件",
"category2": "20002",
"categoryName2": "手机通讯",
"categoryId": "20006",
"published": "1",
"simBuyType": "",
"partNumber": "000000012389328846",
"context": "/emall",
"uuid": "45c799d2-a24e-4d6c-a996-1eb410890d3d",
"brandCode": "0021",
"brandId": "000060021",
"clusterMap": [{
"color": "10007",
"itemCuPartNumber": [{
"versionId": "20013",
"partNumber": "000000012389328865",
"itemType": "10"
}, {"versionId": "20001", "partNumber": "000000012389328850", "itemType": "10"}, {
"versionId": "20007",
"partNumber": "000000012389328858",
"itemType": "10"
}]
}, {
"color": "10010",
"itemCuPartNumber": [{
"versionId": "20013",
"partNumber": "000000012389328862",
"itemType": "10"
}, {"versionId": "20001", "partNumber": "000000012389328847", "itemType": "10"}, {
"versionId": "20007",
"partNumber": "000000012389328855",
"itemType": "10"
}]
}, {
"color": "10013",
"itemCuPartNumber": [{
"versionId": "20013",
"partNumber": "000000012389328863",
"itemType": "10"
}, {"versionId": "20001", "partNumber": "000000012389328848", "itemType": "10"}, {
"versionId": "20007",
"partNumber": "000000012389328856",
"itemType": "10"
}]
}, {
"color": "10001",
"itemCuPartNumber": [{
"versionId": "20013",
"partNumber": "000000012389328859",
"itemType": "10"
}, {"versionId": "20001", "partNumber": "000000012389328845", "itemType": "10"}, {
"versionId": "20007",
"partNumber": "000000012389328851",
"itemType": "10"
}]
}, {
"color": "10004",
"itemCuPartNumber": [{
"versionId": "20013",
"partNumber": "000000012389328860",
"itemType": "10"
}, {"versionId": "20001", "partNumber": "000000012389328846", "itemType": "10"}, {
"versionId": "20007",
"partNumber": "000000012389328852",
"itemType": "10"
}]
}, {
"color": "10016",
"itemCuPartNumber": [{
"versionId": "20013",
"partNumber": "000000012389601057",
"itemType": "10"
}, {"versionId": "20001", "partNumber": "000000012389601043", "itemType": "10"}, {
"versionId": "20007",
"partNumber": "000000012389601049",
"itemType": "10"
}]
}],
"colorList": [{"colorid": "10001", "partNumber": "000000012389328859", "itemType": "10"}, {
"colorid": "10004",
"partNumber": "000000012389328860",
"itemType": "10"
}, {"colorid": "10010", "partNumber": "000000012389328862", "itemType": "10"}, {
"colorid": "10013",
"partNumber": "000000012389328863",
"itemType": "10"
}, {"colorid": "10007", "partNumber": "000000012389328865", "itemType": "10"}, {
"colorid": "10016",
"partNumber": "000000012389601057",
"itemType": "10"
}],
"pic": "//imgservice.suning.cn/uimg1/b2c/image/fsCtx3BFjMBrxh_yLLENwQ.jpg_400w_400h_4e",
"itemDomain": "//" + document.location.hostname,
"resRoot": "//script.suning.cn/project/pdsWeb",
"shopCount": 1,
"sellerDomain": "//www.suning.com/sellers/",
"controller": [{
"FOURBIGPOLY": "120",
"PRICE_FLAG": "1",
"FOURTIMEPAGE": "120",
"FOUR_ACCESSORY_INFO": "120",
"FOURDESC": "120",
"FOUR_PSS_ACTIVITY": "120"
}],
"imageCount": 5,
"context": "/emall",
"storeId": "10052",
"online": "online.suning.com",
"apsDomain": "//apscore.suning.com/",
"newImageDomianDir": "//image1.suning.cn",
"apsId": "",
"reviewNew": "//review.suning.com/",
"pcShopListChange": 0,
"memberDomain": "member.suning.com",
"renxfSwitch": "1",
"cookieDomain": ".suning.com",
"searchDomain": "//search.suning.com/emall/",
"businessType": "",
"pdsRelationURl": "/project/pdsWeb/",
"qrCodeDomain": "//ma.suning.com",
"qrCodeDomainNew": "//code.suning.cn",
"qrCodeLongUrl": "//res.m.suning.com",
"vipDomain": "//vip.suning.com",
"imgHost": "//image?.suning.cn",
"shopName": "苏宁",
"cShopStatus": "",
"yxImRoot": "//istore.suning.com/im-web/",
"treatCode": "",
"buyCode": "",
"jypwCatenIds": "R9004701",
"ipServiceHost": "//ipservice.suning.com",
"storeServiceRoot": "//store.suning.com/",
"tmImageDomianDir": "//image1.suning.cn",
"imgHostTag": "?",
"saleVolume": 0,
"imgHostNumber": "5",
"imgUrlStarNum": "1",
"legouVendor": "0070076553",
"vbuyDomain": "//vbuy.suning.com",
"pgFlag": "10051_4",
"passPartNumber": "000000012389328846",
"flagshipid": "0030000400",
"flagshipName": "Apple产品苏宁自营旗舰店",
"tuijianCatenIds": ["R1901001", "R1202001", "R1207002", "R1207001", "R1204001", "R1304001", "R1502001", "R1502002", "R9000844", "R1704002", "R1501001", "R9003540", "R1501005", "R9000843", "R0128002", "R0128001", "R1701002", "R0191001", "R1301001", "R1301002", "R0151001", "R0151004", "R1302005", "R1702003", "R1702004", "R0104001", "R0104002", "R0105001", "R0105002", "R0503002", "R0504001", "R2601001", "R2601005", "R2402001"],
"comPartNumbers": [],
"moisDomain": "//mois.suning.com",
"curShopName": "",
"swlShopFlag": false,
"hwgShopFlag": false,
"csSwlShopFlag": false,
"tmShopFlag": false,
"phoneFlag": "Y",
"donateID": "R9004987",
"pageType": "1",
"brandName": "Apple",
"newResServer": "//res.suning.cn",
"aqPhone": "https://aq.suning.com/asc/mobile/check.do",
"paySuning": "https://passport.suning.com/ids/trustLogin?sysCode=epp&targetUrl=https://pay.suning.com/epp-epw/quickPay/quick-pay-contract!showBankList.action",
"selectedDistrictName": "",
"broadBandId": "",
"rxfCompetency": "//sncfc.suning.com/sncfc-tps/creditpay/acctauth.do",
"shopStatus": "",
"amDetailLink": "//hc.suning.com/help/channel-153317729649767636.htm",
"amDetail": "退货细则及服务",
"amPdsRelation": "//res.suning.cn/project/pdsWeb/",
"amAbroadDetailLink": "//help.suning.com/page/channel-258.htm",
"amAbroadDetail": "退货细则及服务",
"amAbroadName": "_12389328846_shbz_tuihuo",
"notSaleProductGroup": "",
"solpUrl": "//solp.suning.com",
"nowDate": "20231112",
"cuxiaoType": "",
"silenceType": "",
"silenceTip": "",
"cuxiaoSoldOut": "",
"notSaleFlag": false,
"newItemDesSwith": "0",
"qkkUrl": "//hyj.suning.com",
"icpsDomain": "//icps.suning.com",
"reserveSwitch": "0",
"govPriceSwitch": "",
"cuxiaoSwitch": "0",
"returnGoodsSwitch": "0",
"icpsPriceStreetId": "01",
"shoplistcacheSwitch": "1",
"oldForNewBrandIds": "00006,00005,00001,00002,00003,00004,00013,00007",
"ecsDomain": "//hx.suning.com",
"bookActionAddcartFlag": "1",
"deliveryFlag": "1",
"cDeliveryFlag": "1",
"fimsFreightSwith": "0",
"fimsDomain": "//fims.suning.com",
"cmmdtyType": "Z001",
"modelName": "iPhone 14",
"qualityUrl": "//qc.suning.com",
"cmsBannerUrl": "//lib.suning.com",
"qualitySwitch": "",
"footTickCatenIds": "R9007701",
"cloudAddcartFlag": "1",
"liquanCount": "11",
"assssDomain": "//assss.suning.com",
"pcssDomain": "//pcsslabel.suning.cn",
"quanUrl": "//quan.suning.com",
"attachList": "000000000945153622-000000000945153674-000000000945153694-000000000945153705-000000000945153716-000000000945154156-000000000945156847-000000000945156852-000000000945156857-000000000945156862-000000000945156867-000000000945156872-000000000945156877-000000000945156882-000000000945156899-000000000945156903-000000000945156906-000000000945156914-000000000945156915-000000000945156921-000000000945156934-000000000945156942",
"reviewTotal": "0",
"luaUrl": "//pas.suning.com",
"hasSidebar": true, /*默认关闭,true为打开*/
"hasBottomFixed": false, /*默认关闭,true为打开*/
"hasTopFixed": false, /*默认关闭,true为打开*/
"qualificationList": "0",
"itemViewFlag": false,
"intelligent": "//dt.suning.com",
"version": "?v=2023110123",
"mjSwitch": "0",
"pageNO": "02",
"smartFlag": false,
"itemSource": "",
"pavilion": "",
"bigpolylogin": "0",
"juDomain": "//ju.suning.com",
"recDomain": "//rec.suning.com",
"pcImportantClause": "本站苏宁自营商品的商品详情信息及包装参数信息均由供应商自行设计、制作并通过苏宁向其开放的数据端口自行发布,其真实性、准确性和合法性由供应商负责。本站保证苏宁自营商品均为正品,但因生产厂家可能会在没有任何提前通知的情况下更改产品包装、产地或者一些附件,本站不能确保用户收到的货物与本站展示的图片、产地、附件说明完全一致。",
"isCShop": false,
"jsdUrl": "//ssds.suning.com/ssds-web",
"seoBreadCrumbName": "AppleiPhone 14手机",
"faqDomain": "//faq.suning.com",
"codUrl": "//smvas.suning.com",
"feastActive": "0",
"pgUrl": "//pin.m.suning.com/pgs/product",
"pgDomain": "//pin.m.suning.com",
"compareCatalog": "0",
"luaPcSosFreight": "0",
"specialSaleFlag": "0",
"jubaoUrl": "//ipp.suning.com/sips/accuseIndex.action",
"showJubao": "0",
"jubaoID": "R0191004,R0501001,R0502001,R0503002,R0504001,R0506002,R0506003,R0508001,R0701002,R0702001,R0801001,R0801003,R0801004,R0801005,R0802002,R0901003,R0901004,R0902002,R1501001,R1501002,R1501005,R1502001,R1502003,R1505003,R1506001,R1506002,R1506003,R1506004,R1506006,R1506007,R1506009,R1506010,R1704002,R1901001,R4402005,R9000548,R9000549,R9000550,R9000551,R9000843,R9000845,R9000846,R9000847,R9000848,R9000849,R9000850,R9000851,R9000852,R9000853,R9000854,R9000855,R9000856,R9000857,R9000858,R9000859,R9000860,R9000861,R9000862,R9000863,R9000864,R9000865,R9000866,R9001146,R9001147,R9001148,R9001149,R9001150,R9001151,R9001152,R9001153,R9001154,R9001155,R9001156,R9001157,R9001158,R9001219,R9001220,R9001221,R9001222,R9001223,R9001224,R9001225,R9001226,R9001227,R9001228,R9001229,R9002112,R9002113,R9002114,R9002115,R9002116,R9002117,R9002118,R9002119,R9002120,R9002121,R9002122,R9002123,R9002124,R9002125,R9002126,R9002127,R9002128,R9002129,R9002130,R9002131,R9002132,R9002133,R9002134,R9002135,R9002136,R9002137,R9002138,R9002139,R9002140,R9002141,R9002142,R9002143,R9002144,R9002145,R9002146,R9002147,R9002148,R9002149,R9002150,R9002151,R9002152,R9002153,R9002154,R9002155,R9002156,R9002157,R9002158,R9002159,R9002160,R9002161,R9002162,R9002163,R9002164,R9002165,R9003434,R9003540,R9003559,R9004516,R9004517,R9004518,R9004519,R9004520,R9004521,R9004522,R9004523,R9004524,R9004525,R9004526,R9004527,R9006049,R9006050,R9006051,R9006052,R9006053,R9006054,R9006055,R9006056,R9006057,R9006058,R9008389,R9008390,R9008391,R9008392",
"showZeroBuy": "0",
"ccfsUrl": "//ccfs.suning.com",
"gotoXiaoYi": "true",
"autoUrl": "//auto.suning.com",
"ppyunDomain": "player.pptvyun.com",
"zyHwgFlag": "",
"mountType": "",
"vendor": "",
"twoFlag": true,
"tmOnlineId": "14266",
"hwgOnlineId": "554312",
"jiwuChatId": "",
"phoneCategoryId": "20006",
"cuxiaoSeq": {
preVoucherTitle: 1,
voucherTitle: 2,
lhvoucherTitle: 3,
isXYuanNItemTitle: 4,
taogouyhTitle: 5,
newTaogouyhTitle: 6,
giftTitle: 7,
limitGifts: 8,
ordersGifts: 9,
jrPromTitle: 10,
purchaseTitle: 11,
couponTitle: 12,
newcouponTitle: 13,
yfbTitle: 14,
rxfTitle: 15,
scodeTitle: 16,
pointTitle: 17,
freightfreeTitle: 18,
govTitle: 19,
jnbtTitle: 20
},
"blackCategoryCode": "R9010501",
"weight": "0.32",
"volume": "445.5",
"isFresh": false,
"scrapeCouponUrl": "//yzdh.suning.com",
"scrapeCoupon": "0",
"isSevenDayOkForTm": "true",
"videoUrl": "https://m4.pptvyun.com/pvod/e11a0/0CoxJ26kjNbrjZMfNE-j7D6_UDw/eyJkbCI6MTY2MzIzMTg1NywiZXMiOjYwNDgwMCwiaWQiOiIwYTJmbXF1WHFhT2duNi1MNEsyZG9hZmhvYVdsbWFhY29LU2MiLCJ2IjoiMS4wIn0/0a2fmquXqaOgn6-L4K2doafhoaWlmaacoKSc.mp4",
"czyHwgFlag": "",
"rxfDomain": "//rxf.suning.com",
"sncfcDomain": "https://sncfc.suning.com",
"overseasFAQ01": "",
"yzCoupon": "1",
"yunfeixianPC": "0",
"pchdfk": "0",
"supervipDomain": "//supervip.suning.com",
"memberRemain": "0",
"passportDomain": "https://loginst.suning.com",
"newServiceLabel": "1",
"tssUrl": "//tss.suning.com",
"cpmAdDomain": "//th.suning.com",
"suningJiWuFlag": false,
"overseasFAQSwitch": "0",
"cpmAdRequestCode": "pid=100003869&pid=100003866",
"orderDomain": "//order.suning.com",
"clothesFlag": "0",
"zyxjLink": "",
"showMUrl": "//show.m.suning.com",
"breadcrumbsShopSwitch": "1",
"fristPic": "//imgservice.suning.cn/uimg1/b2c/image/fsCtx3BFjMBrxh_yLLENwQ.jpg",
"gyFlag": false,
"c2mFlag": false,
"ypFlag": false,
"mainPicDynamicUrlSwitch": "1",
"virtualFlag": false,
"solsUrl": "//sols.suning.com",
"realNameUrl": "//mpay.suning.com/epwm/identity/toIdentityVerification.htm?source=20&backUrl=",
"businessFlag": "",
"businessField": "",
"snassUrl": "//snasss.suning.com",
"plmsUrl": "//plmslabel.suning.cn",
"spesUrl": "//spes.suning.com",
"envName": "PROD",
"goodShopLabelCode": "C00000023",
"jumUrl": "//ju.suning.com",
"supermarketCheck": "",
"sntkUrl": "//sntk.suning.com",
"sucLabel": "0",
"usedCarFlag": "",
"usedCarPrice": "",
"usedCarOriginalPrice": "",
"czHwgFlag": "", /*0422号卡用券开关*/
"haokaYongQuanSwitch": "1",
"payapiDomain": "//payapi.suning.com",
"ftpgsDomain": "",
"rentType": "",
"installCode": "",
"dsmsUrl": "//dsms.suning.com",
"entryPermissionCode": "015738",
"subPrdType": "",
"mysnUrl": "",
"cpmDatasGroupCode": "pid=100004623",
"diamondInfoSwitch": "1",
"newCarShowFlag1908": "1",
"newCarFlag": "",
"bestCouponsSwitch": "1",
"sntmDomain": "//sntm.suning.com",
"uireDomain": "//uirecore.suning.com",
"favoriteUrl": "//favorite.suning.com",
"iarwebDomain": "//iar-web.suning.com",
"tmLabelFromSolpSwitch": "1",
"userCarDetailUrl": false,
"coldChainFlag": "01",
"atmospherePicSwitch": "1",
"o2oDataTransferSwitch": "1",
"sslFlag": "",
"ctSslFlag": "",
"sslStoreCode": "",
"addCartNumLimit": "199",
"favoriteStatusSwitch": "1" == "1",
"thirdEVoucherFlag": "",
"specialSSLFlag": "",
"sslLabelText": "苏宁服务",
"packageYhSwith": "1",
"sellPointSwith": "1",
"recommandBusinessDoamin": "//rods.suning.com",
"reDomain": "//re.suning.com",
"offSaleRecomFlag": "1"
}; /*窄屏不展示右侧工具条*/
if (window.screen.width