如何获取由javascript计算创建的数据

2024-07-02 12:23:44 发布

您现在位置:Python中文网/ 问答频道 /正文

有一个网站http://www.swadpia.co.kr/goods/goods_view/CNC1000/GNC1001

在这个网站上,有许多选择,如大小,颜色等。。 当我选择一个选项时,总价格会改变

我认为这个价格是由javascript生成的。
如何使用python获取数据?
我想把所有的总价加上许多选择


Tags: viewhttp网站颜色www选项价格javascript
2条回答

你应该这样做

import json
from urllib.request import urlopen
from pprint import pprint

url = "http://www.swadpia.co.kr/estimate/estimate_goods/json_data"
data = json.load(urlopen(url))

for key, value in data.items():
    pprint("Key:")
    pprint(key)

这将产生一个屏幕输出

'Key:'
'paper_kind'
'Key:'
'paper_type'
'Key:'
'paper_type_print'
'Key:'
'paper_info'
'Key:'
'size_info'
'Key:'
'print_info1'
'Key:'
'print_info2'
'Key:'
'print_info3'
'Key:'
'print_info4'

现在您拥有了所有键、值对

或者类似的

url = "http://www.swadpia.co.kr/estimate/estimate_goods/json_data"
data = json.load(urlopen(url))

print (type(data))

for key in data:
    if (key == 'paper_kind'):
        print ("key: %s , value: %s" % (key, data[key]))

比你还厉害

<class 'dict'>
key: paper_kind , value: [{'common_code': 'PKD10', 'code_name': '일반지'}, {'common_code': 'PKD20', 'code_name': '고급지'}, {'common_code': 'PKD30', 'code_name': '특수지'}, {'common_code': 'PKD40', 'code_name': '(펄)지'}, {'common_code': 'PKD50', 'code_name': '하드커버지'}, {'common_code': 'PKD60', 'code_name': '카드/투명명함'}, {'common_code': 'PKD70', 'code_name': '스티커'}, {'common_code': 'PKD71', 'code_name': '스티커 롤'}, {'common_code': 'PKD80', 'code_name': '판지'}, {'common_code': 'PKD90', 'code_name': 'NCR'}, {'common_code': 'PKD91', 'code_name': '플라스틱&비닐'}]

您可以在这个JSON文件中找到所需的所有数据

^{}

相关问题 更多 >