希望对BS4有良好经验的任何人都可以帮助我。我很头疼 我要获取:产品标题,价格,图片和网址来自
https://www.offspring.co.uk/view/category/offspring_catalog/NEWIN?pageSize=100&sort=-releasedate 产品。
我已经用以下代码获得了price
和href (url)
:
价格= url.find("div", "price js-price")
(价格)
Purl = url.find("a").attrs['href']
(URL)
但是图片给我带来了问题:
图片= url.find("img").attrs["src"]
,更重要的是我不知道如何获得产品标题,因为就像在一个怪异的课堂上一样。
例如,在最后一个名为Jordan Zoom 92 Trainer
的项目上,我想获得这个名称,但是不确定要做什么:)
如果您不想访问链接,则为图片。 picture
非常感谢<3
答案 0 :(得分:0)
要提取有关每种产品的信息,可以使用以下示例:
import json
import requests
from bs4 import BeautifulSoup
url = 'https://www.offspring.co.uk/view/category/offspring_catalog/NEWIN?pageSize=100&sort=-releasedate'
soup = BeautifulSoup(requests.get(url).content, 'html.parser')
for i in soup.select('.productList_item'):
link = 'https://www.offspring.co.uk' + i.a['href']
brand = i.strong.text
name = i.br.find_next_sibling(text=True).strip()
price = i.select_one('.price, .now_price')['data-value']
picture_url = json.loads(i.img['data-media'])['350']
print('{:<20} {:<35} {:<10} {:<70} {}'.format(brand, name, price, picture_url, link))
打印:
Jordan Jordan Zoom '92 Trainers 130.0 https://i1.adis.ws/i/office/4022015374_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4022015374
Comme Des Garcons Cdg Cross Trainers 535.0 https://i1.adis.ws/i/office/4133010000_sd1.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4133010000
Comme Des Garcons Cdg Cross Trainers 535.0 https://i1.adis.ws/i/office/4133000000_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4133000000
adidas Paris Trainers 74.99 https://i1.adis.ws/i/office/4022535270_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4022535270
Nike Vapormax 2020 Trainers 190.0 https://i1.adis.ws/i/office/4016724556_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4016724556
Nike Vapormax 2020 Trainers 190.0 https://i1.adis.ws/i/office/4016724555_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4016724555
adidas Statement Hoddlesden Spzl Trainers 50.0 https://i1.adis.ws/i/office/3555150000_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/3555150000
Puma Bluebird Trainers 74.99 https://i1.adis.ws/i/office/4033135280_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4033135280
On-Running Cloud X Trainers 130.0 https://i1.adis.ws/i/office/4131410508_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4131410508
On-Running Cloud Trainers 120.0 https://i1.adis.ws/i/office/4129108801_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4129108801
On-Running Cloudswift Trainers 135.0 https://i1.adis.ws/i/office/4128915798_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4128915798
On-Running Cloudswift Trainers 135.0 https://i1.adis.ws/i/office/4128908800_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4128908800
On-Running Cloudswift Trainers 135.0 https://i1.adis.ws/i/office/4128908799_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4128908799
On-Running Cloudswift Trainers 135.0 https://i1.adis.ws/i/office/4128908798_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4128908798
On-Running Cloudswift Trainers 135.0 https://i1.adis.ws/i/office/4128908789_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4128908789
On-Running Cloudswift Trainers 135.0 https://i1.adis.ws/i/office/4128908788_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4128908788
Filling Pieces Low Plain Court Trainers 175.0 https://i1.adis.ws/i/office/4122114879_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4122114879
Filling Pieces Mondo 2.0 Ripple Trainers 170.0 https://i1.adis.ws/i/office/3556324666_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/3556324666
Filling Pieces Mondo 2.0 Ripple Trainers 170.0 https://i1.adis.ws/i/office/3556304550_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/3556304550
Filling Pieces Low Mondo Ripple Trainers 170.0 https://i1.adis.ws/i/office/2991230475_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/2991230475
Converse All Star Hi 70s Trainers 79.99 https://i1.adis.ws/i/office/1662415290_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/1662415290
adidas Stan Smith Trainers 74.99 https://i1.adis.ws/i/office/2143115498_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/2143115498
adidas Y3 Y-3 Shiku Run Trainers 300.0 https://i1.adis.ws/i/office/4084815638_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4084815638
adidas Y3 Y-3 Shiku Run Trainers 300.0 https://i1.adis.ws/i/office/4084808675_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4084808675
adidas Y3 Y-3 Shiku Run Trainers 300.0 https://i1.adis.ws/i/office/4084808673_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4084808673
adidas Delpala Trainers 54.99 https://i1.adis.ws/i/office/4037704470_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4037704470
adidas Superstar Bold Trainers 89.99 https://i1.adis.ws/i/office/2669108370_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/2669108370
adidas Stan Smith Trainers 74.99 https://i1.adis.ws/i/office/2143115262_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2143115262
adidas Stan Smith Trainers 74.99 https://i1.adis.ws/i/office/2143114446_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2143114446
Converse All Star Ox 70s Trainers 74.99 https://i1.adis.ws/i/office/1662315290_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/1662315290
adidas Superstar Trainers 79.99 https://i1.adis.ws/i/office/3844515498_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/3844515498
Nike Air Max 95 150.0 https://i1.adis.ws/i/office/2026496414_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2026496414
Nike Nike Elemental Backpack 2.0 24.99 https://i1.adis.ws/i/office/3891380954_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/3,87/3891380954
adidas Zx 8000 Trainers 89.99 https://i1.adis.ws/i/office/2125815184_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/2125815184
adidas Zx 500 Trainers 74.99 https://i1.adis.ws/i/office/2120067342_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2120067342
adidas Boston Super Trainers 74.99 https://i1.adis.ws/i/office/1672963106_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/1672963106
adidas Zx 500 Trainers 74.99 https://i1.adis.ws/i/office/1511624536_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/1511624536
Puma Bluebird Trainers 74.99 https://i1.adis.ws/i/office/4033163114_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4033163114
Nike Space Hippie 4 125.0 https://i1.adis.ws/i/office/4015340811_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4015340811
Nike Space Hippie 1 115.0 https://i1.adis.ws/i/office/3944508765_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/3944508765
adidas Padiham Spezials 74.99 https://i1.adis.ws/i/office/3133467370_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/3133467370
Comme Des Garcons Spalwart Runners 275.0 https://i1.adis.ws/i/office/4133165000_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4133165000
Comme Des Garcons Spalwart Runners 275.0 https://i1.adis.ws/i/office/4133160000_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4133160000
Comme Des Garcons Spalwart Runners 275.0 https://i1.adis.ws/i/office/4133140000_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4133140000
adidas As 520 Trainers 74.99 https://i1.adis.ws/i/office/4022663107_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4022663107
adidas As 520 Trainers 74.99 https://i1.adis.ws/i/office/4022652524_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4022652524
Jordan Jordan Delta Trainers 130.0 https://i1.adis.ws/i/office/3936715372_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/3936715372
Nike Air Max Plus 3 Trainers 150.0 https://i1.adis.ws/i/office/3777708415_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/3777708415
Nike Daybreak Trainers 89.99 https://i1.adis.ws/i/office/3557108431_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/3557108431
adidas Stadt Trainers 84.99 https://i1.adis.ws/i/office/3538480932_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/3538480932
adidas Stella McCartney Ultraboost 20s Trainers 200.0 https://i1.adis.ws/i/office/4066340820_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4066340820
Veja Campo Trainers 115.0 https://i1.adis.ws/i/office/3427115427_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/3427115427
adidas Stella McCartney Treino Trainers 160.0 https://i1.adis.ws/i/office/2901715555_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/2901715555
Vans Sk8-Hi Slim Trainers 64.99 https://i1.adis.ws/i/office/1050408494_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/1050408494
adidas Stella McCartney Boston S Trainers 180.0 https://i1.adis.ws/i/office/4065815410_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4065815410
adidas Stella McCartney Boston S Trainers 180.0 https://i1.adis.ws/i/office/4065808567_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4065808567
Vans Sk8 Hi Mte 2.0 Dx Trainers 100.0 https://i1.adis.ws/i/office/4027396439_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4027396439
Vans Old Skool Trainers 74.99 https://i1.adis.ws/i/office/2421896435_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/2421896435
Nike Air Max III Trainers 130.0 https://i1.adis.ws/i/office/4016615343_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4016615343
adidas Zx8000 Trainers 110.0 https://i1.adis.ws/i/office/2164415678_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/2164415678
Jordan Air Jordan Og Trainers 125.0 https://i1.adis.ws/i/office/3873703617_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/3873703617
Jordan Jordan Zoom '92 Trainers 130.0 https://i1.adis.ws/i/office/4022008450_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4022008450
Nike Nike Flow 2020 Ispa Trainers 155.0 https://i1.adis.ws/i/office/4063667382_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4063667382
Nike Nike Flow 2020 Ispa Trainers 155.0 https://i1.adis.ws/i/office/4063666824_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4063666824
Puma Puma Oslo Trainers 79.99 https://i1.adis.ws/i/office/1352112146_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/1352112146
Puma Puma Oslo Trainers 79.99 https://i1.adis.ws/i/office/1352111797_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/1352111797
adidas Sl 72 Trainers 69.99 https://i1.adis.ws/i/office/3843115257_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/3843115257
Nike Air Force 1 07 Trainers 110.0 https://i1.adis.ws/i/office/2704615626_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/2704615626
Vans Vans Classic Slip Ons 54.99 https://i1.adis.ws/i/office/2496515408_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2496515408
Jordan Air Jordan 6 Trainers 170.0 https://i1.adis.ws/i/office/1642387429_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/1642387429
Nike Air Max 90 Flyease Trainers 115.0 https://i1.adis.ws/i/office/4020803617_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4020803617
Nike 70's Type Trainers 79.99 https://i1.adis.ws/i/office/4015815319_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4015815319
adidas Y3 Y-3 Sprint Trainers 250.0 https://i1.adis.ws/i/office/4003101110_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4003101110
Jordan Jordan Delta Trainers 115.0 https://i1.adis.ws/i/office/3936724545_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/3936724545
adidas Y3 Y-3 Yohji Star Trainers 229.0 https://i1.adis.ws/i/office/3887100000_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/3887100000
adidas Y3 Y-3 Yohji Pro Trainers 229.0 https://i1.adis.ws/i/office/3886900000_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/3886900000
Nike Air Force 1 07 Trainers 84.99 https://i1.adis.ws/i/office/2583208441_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/2583208441
Nike Blazer Mid 77 Trainers 89.99 https://i1.adis.ws/i/office/1174377157_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/1174377157
Converse Run Star Hike Trainers 89.99 https://i1.adis.ws/i/office/3543677146_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/3543677146
Converse Run Star Hike Trainers 89.99 https://i1.adis.ws/i/office/3543640809_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/3543640809
Jordan Air Jordan 3 170.0 https://i1.adis.ws/i/office/1641815508_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/1641815508
adidas Zx 1000 Trainers 74.99 https://i1.adis.ws/i/office/4095915679_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4095915679
Vans Backpack 46.99 https://i1.adis.ws/i/office/4028396449_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/3,87/4028396449
Vans Crew Socks 12.99 https://i1.adis.ws/i/office/4028296448_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/3,87/4028296448
Vans Ss T-shirt 46.99 https://i1.adis.ws/i/office/4028196446_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/3,87/4028196446
Vans Shallow Unstructed Cap 27.99 https://i1.adis.ws/i/office/4028096445_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/3,87/4028096445
Vans Sk8 Low Trainers 64.99 https://i1.adis.ws/i/office/4027296438_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4027296438
Vans Comfycush Slip On Trainers 69.99 https://i1.adis.ws/i/office/3823196432_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/3823196432
Vans Sk8 Hi Zip Toddler Trainers 39.99 https://i1.adis.ws/i/office/2838496436_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/4,85/2838496436
Vans Authentic Kids Trainers 36.99 https://i1.adis.ws/i/office/2615596440_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/4,85/2615596440
Vans Classic Slip On Kids Trainers 36.99 https://i1.adis.ws/i/office/2608196443_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/4,85/2608196443
Vans Classic Slip On Toddlers 32.99 https://i1.adis.ws/i/office/2607396442_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/4,85/2607396442
Vans Classic Slip On Toddlers Trainers 32.99 https://i1.adis.ws/i/office/2607396441_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/4,85/2607396441
Vans Old Skool Trainers 69.99 https://i1.adis.ws/i/office/2421896434_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2421896434
Vans Sk8 Hi Trainers 74.99 https://i1.adis.ws/i/office/2421696437_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2421696437
Vans Sk8 Hi Trainers 74.99 https://i1.adis.ws/i/office/2421696436_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2421696436
Vans Era Trainers 59.99 https://i1.adis.ws/i/office/2209196433_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2209196433
Vans Sk8 Hi Kids Trainers 49.99 https://i1.adis.ws/i/office/1834196436_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/4,85/1834196436
Converse Jack Purcell Trainers 84.99 https://i1.adis.ws/i/office/2413215636_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/2413215636
Converse Jack Purcell Trainers 84.99 https://i1.adis.ws/i/office/2413208670_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/2413208670