|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
结果:{'Dark Grey': 20, 'Beige': 21, 'White': 13, 'Dark Red': 9, 'Olive': 3, 'Gray': 36, 'Pink': 12, 'Black': 37, 'Ecru': 4, 'Navy': 24, 'Fuchsia': 2}
import requests
from lxml import etree
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36'
}
colors=[]
def parser_page(url):
try:
resp = requests.get(url,headers=headers)
text = resp.text
html = etree.HTML(text)
data = html.xpath('//div[@id="cm_cr-review_list"]//a[@data-hook]/span/text()')
for color in data:
color = color.split(":")[1].strip()
colors.append(color)
print(colors)
except Exception as e:
print("出现异常-->"+str(e))
def main():
base_url='https://www.amazon.co.uk/4sold-Rita-Womens-Knitted-Snowboard/product-reviews/B01LDCDDOS/?ie=UTF8&reviewerType=all_reviews&pageNumber={}'
for x in range(1,20):
url=base_url.format(x)
parser_page(url)
d = {}
for color in colors:
if not color in d:
d[color]=1
else:
d[color]=d[color]+1
print(d)
if __name__ =='__main__':
main()
|
|