1 回答
TA贡献1777条经验 获得超10个赞
要获取产品的名称、链接和价格,您可以使用以下示例:
import requests
from bs4 import BeautifulSoup
url = 'https://www.footlocker.co.uk/INTERSHOP/web/FLE/Footlocker-Footlocker_GB-Site/en_GB/-/GBP/ViewStandardCatalog-ProductPagingAjax?SearchParameter=____&sale=new&MultiCategoryPathAssignment=all&PageNumber={}'
for page in range(3): # <--- increase the number of pages here
print('Page {}...'.format(page))
data = requests.get(url.format(page)).json()
soup = BeautifulSoup(data['content'], 'html.parser')
for d in soup.select('[data-request]'):
s = BeautifulSoup(requests.get(d['data-request']).json()['content'], 'html.parser')
print(s.select_one('[itemprop="name"]').text)
print(s.select_one('[itemprop="price"]')['content'], s.select_one('[itemprop="priceCurrency"]')['content'])
print(s.a['href'])
print('-' * 80)
印刷:
Page 0...
adidas Performance Don Issue 2 - Men Shoes
84.99 GBP
https://www.footlocker.co.uk/en/p/adidas-performance-don-issue-2-men-shoes-92815?v=314102617504
--------------------------------------------------------------------------------
Nike Air Force 1 Crater - Women Shoes
94.99 GBP
https://www.footlocker.co.uk/en/p/nike-air-force-1-crater-women-shoes-98071?v=315349054502
--------------------------------------------------------------------------------
Jordan Jumpmcn Cl Iii Camo - Baby Tracksuits
39.99 GBP
https://www.footlocker.co.uk/en/p/jordan-jumpmcn-cl-iii-camo-baby-tracksuits-91611?v=318280390044
--------------------------------------------------------------------------------
Jordan 13 Retro - Grade School Shoes
99.99 GBP
https://www.footlocker.co.uk/en/p/jordan-13-retro-grade-school-shoes-952?v=316701533404
--------------------------------------------------------------------------------
...and so on.
添加回答
举报