1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > 手札-11(京东实战手札)

手札-11(京东实战手札)

时间:2021-08-28 15:00:01

相关推荐

手札-11(京东实战手札)

你好,我是悦创。

先修知识:str.find():>>> Python find()

"""project = 'Code', file_name = 'test', author = 'AI悦创'time = '/3/13 19:21', product_name = PyCharm# code is far away from bugs with the god animal protectingI love animals. They taste delicious."""import requestsimport jsonurl = '/comment/productCommentSummaries.action?referenceIds=29505771199&callback=jQuery7981360'html = requests.get(url).textstart_position = html.find('{"CommentsCount":')end_position = html.find('"PoorRateStyle":0}]}') + len('"PoorRateStyle":0}]}')result = html[start_position: end_position]res = json.loads(result)print(len(res['CommentsCount']))print(res['CommentsCount'][0]['DefaultGoodCountStr'])dict_data = res['CommentsCount'][0]result = dict_data.get('DefaultGoodCountStr', None)print(result)

运行结果:

110+10+

尝试第二个链接:

"""project = 'Code', file_name = 'test', author = 'AI悦创'time = '/3/13 19:21', product_name = PyCharm# code is far away from bugs with the god animal protectingI love animals. They taste delicious."""import requestsimport json# url = '/comment/productCommentSummaries.action?referenceIds=29505771199&callback=jQuery7981360'url = '/comment/productCommentSummaries.action?referenceIds=12353915&callback=jQuery7981360'html = requests.get(url).textstart_position = html.find('{"CommentsCount":')end_position = html.find('"PoorRateStyle":0}]}') + len('"PoorRateStyle":0}]}')result = html[start_position: end_position]res = json.loads(result)print(len(res['CommentsCount']))print(res['CommentsCount'][0]['DefaultGoodCountStr'])dict_data = res['CommentsCount'][0]result = dict_data.get('DefaultGoodCountStr', None)print(result)

运行结果:

112万+12万+

多个商品 id

import requestsimport json# 多个商品 idurl = '/comment/productCommentSummaries.action?referenceIds=12353915,11993134&callback=jQuery7981360'html = requests.get(url).textstart_position = html.find('{"CommentsCount":')end_position = html.find('"PoorRateStyle":0}]}') + len('"PoorRateStyle":0}]}')result = html[start_position: end_position]res = json.loads(result)# 第一个 idprint('第一个 id')print(len(res['CommentsCount']))print(res['CommentsCount'][0]['DefaultGoodCountStr'])dict_data = res['CommentsCount'][0]result = dict_data.get('DefaultGoodCountStr', None)print(result)# 第二个 idprint('第二个 id')print(len(res['CommentsCount']))print(res['CommentsCount'][1]['DefaultGoodCountStr'])dict_data = res['CommentsCount'][1]result = dict_data.get('DefaultGoodCountStr', None)print(result)

运行结果:

第一个 id212万+12万+第二个 id223万+23万+

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。