最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

手札

IT圈 admin 17浏览 0评论

手札

你好,我是悦创。

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

"""
project = 'Code', file_name = 'test', author = 'AI悦创'
time = '2020/3/13 19:21', product_name = PyCharm
# code is far away from bugs with the god animal protectingI love animals. They taste delicious.
"""
import requests
import json
url = '.action?referenceIds=29505771199&callback=jQuery7981360'html = requests.get(url).text
start_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)

运行结果:

1
10+
10+

尝试第二个链接:

"""
project = 'Code', file_name = 'test', author = 'AI悦创'
time = '2020/3/13 19:21', product_name = PyCharm
# code is far away from bugs with the god animal protectingI love animals. They taste delicious.
"""
import requests
import json
# url = '.action?referenceIds=29505771199&callback=jQuery7981360'
url = '.action?referenceIds=12353915&callback=jQuery7981360'
html = requests.get(url).text
start_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)

运行结果:

1
12万+
12万+

多个商品 id

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

运行结果:

第一个 id
2
12万+
12万+
第二个 id
2
23万+
23万+

手札

你好,我是悦创。

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

"""
project = 'Code', file_name = 'test', author = 'AI悦创'
time = '2020/3/13 19:21', product_name = PyCharm
# code is far away from bugs with the god animal protectingI love animals. They taste delicious.
"""
import requests
import json
url = '.action?referenceIds=29505771199&callback=jQuery7981360'html = requests.get(url).text
start_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)

运行结果:

1
10+
10+

尝试第二个链接:

"""
project = 'Code', file_name = 'test', author = 'AI悦创'
time = '2020/3/13 19:21', product_name = PyCharm
# code is far away from bugs with the god animal protectingI love animals. They taste delicious.
"""
import requests
import json
# url = '.action?referenceIds=29505771199&callback=jQuery7981360'
url = '.action?referenceIds=12353915&callback=jQuery7981360'
html = requests.get(url).text
start_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)

运行结果:

1
12万+
12万+

多个商品 id

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

运行结果:

第一个 id
2
12万+
12万+
第二个 id
2
23万+
23万+
发布评论

评论列表 (0)

  1. 暂无评论