Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Web抓取跨度标记,带BeautifulSoup4,价格为英镑_Python_Html_Regex_Web Scraping - Fatal编程技术网

Python Web抓取跨度标记,带BeautifulSoup4,价格为英镑

Python Web抓取跨度标记,带BeautifulSoup4,价格为英镑,python,html,regex,web-scraping,Python,Html,Regex,Web Scraping,第一个帖子,所以请温柔一点。我正在尝试使用Python进行web刮取 我的目标是制作一个可以访问以下页面的脚本: WWWzaraDOTcom/uk/en/sale/woman/dresses/view-all-c731533.html 我希望脚本返回a.name.item,即数据ecirp中的数据,其中span类分别是sale和crossOut对角线 我想在其他网站上使用这个脚本的时间 我下面的代码可以访问Zara、拉页面和在RE/BS中操作——但在谷歌搜索了很多BeautifulSoup和sp

第一个帖子,所以请温柔一点。我正在尝试使用Python进行web刮取

我的目标是制作一个可以访问以下页面的脚本:

WWWzaraDOTcom/uk/en/sale/woman/dresses/view-all-c731533.html

我希望脚本返回a.name.item,即数据ecirp中的数据,其中span类分别是sale和crossOut对角线

我想在其他网站上使用这个脚本的时间

我下面的代码可以访问Zara、拉页面和在RE/BS中操作——但在谷歌搜索了很多BeautifulSoup和span标签之后,我无法拉任何价格

正则表达式有点伤了我的大脑,我无法从我的书中得到任何简单的代码示例来使用IRL

教美女群正确穿越的答案是什么 或者使用RE从集合字符串推断值? 或者我应该采取另一种更好的方法。我想在商品最终上市时提醒大家

import requests
import re

r =      requests.get(“http://www.zara.com/uk/en/sale/woman/dresses/view-all-c731533.html”)
r.raise_for_status() 
html = r.text
soup = BeautifulSoup(html, 'html.parser')

您需要的所有数据都在产品信息标签中,url也不同,因为您必须首先选择一个地区:

import requests

from bs4 import BeautifulSoup
r =   requests.get("http://www.zara.com/ie/en/sale/woman/dresses/view-all-c731533.html?#utm_referrer=http%3A%2F%2Fwww.zara.com%2F%3Fgo%3Dhttp%253A%2F%2Fwww.zara.com%2Fshare%2Fsale%2Fwoman%2Fdresses%2Fview-all-c731533.html")
r.raise_for_status()
html = r.text
soup = BeautifulSoup(html)
prods = soup.find_all("div", {"class": "product-info"})
print(prods)
for p in prods:
    print(p.a.text)
    print("Old price  {}".format(p.find("span", {"class": "crossOut"})["data-ecirp"]))
    print("New price {}".format(p.find("span", {"class": "sale"})["data-ecirp"]))
输出:

ZIP-BACK TUBE DRESS
Old price  49.95  EUR
New price 29.99  EUR
SEQUINNED DRESS
Old price  69.95  EUR
New price 29.99  EUR
HALTER NECK SHIMMER THREAD DRESS
Old price  39.95  EUR
New price 25.99  EUR
CREPE SLEEVELESS DRESS
Old price  49.95  EUR
New price 29.99  EUR
OTTOMAN RIB DRESS
Old price  39.95  EUR
New price 25.99  EUR
SHORT LACE DRESS
Old price  49.95  EUR
New price 39.99  EUR
SPARKLY VELVET DRESS
Old price  49.95  EUR
New price 29.99  EUR
DRESS WITH SIDE GATHERING
Old price  19.95  EUR
New price 12.99  EUR
TUBE DRESS WITH STRAPPY BACK
Old price  59.95  EUR
New price 49.99  EUR
SKATER DRESS
Old price  49.95  EUR
New price 39.99  EUR
PARTY DRESS
Old price  49.95  EUR
New price 29.99  EUR
DOUBLE LAYER DRESS
........................
                               name    old    new  saving  precent_saving
0                 ZIP-BACK TUBE DRESS  49.95  29.99   19.96       39.959960
1                     SEQUINNED DRESS  69.95  29.99   39.96       57.126519
2    HALTER NECK SHIMMER THREAD DRESS  39.95  25.99   13.96       34.943680
3              CREPE SLEEVELESS DRESS  49.95  29.99   19.96       39.959960
4                   OTTOMAN RIB DRESS  39.95  25.99   13.96       34.943680
5                    SHORT LACE DRESS  49.95  39.99    9.96       19.939940
6                SPARKLY VELVET DRESS  49.95  29.99   19.96       39.959960
7           DRESS WITH SIDE GATHERING  19.95  12.99    6.96       34.887218
8        TUBE DRESS WITH STRAPPY BACK  59.95  49.99    9.96       16.613845
9                        SKATER DRESS  49.95  39.99    9.96       19.939940
10                        PARTY DRESS  49.95  29.99   19.96       39.959960
11                 DOUBLE LAYER DRESS  29.95  17.99   11.96       39.933222
将数据存储在dict中可能是个好主意:

from collections import defaultdict
d = defaultdict(defaultdict)
for p in prods:
    k = p.a.text
    v1 = p.find("span", {"class": "crossOut"})["data-ecirp"]
    v2 = p.find("span", {"class": "sale"})["data-ecirp"]
    d[k]["new_price"] = v1
    d[k]["old_price"] = v2
    d[k]["saving"] = float(v1.split()[0]) - float(v2.split()[0])

print(d)
这将给你:

defaultdict(<class 'collections.defaultdict'>, {'': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 11.96, 'old_price': '17.99  EUR'}),
 'CROCHET DRESS': defaultdict(None, {'new_price': '49.95  EUR','saving': 19.960000000000004, 'old_price': '29.99  EUR'}),
 'BASIC SLEEVELESS DRESS': defaultdict(None, {'new_price': '14.95  EUR', 'saving': 4.959999999999999, 'old_price': '9.99  EUR'}), 'FLORAL PRINT TUNIC': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'COMBINED DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'SEQUINNED DRESS': defaultdict(None, {'new_price': '69.95  EUR', 'saving': 39.96000000000001, 'old_price': '29.99  EUR'}), 'LONG CROCHET DRESS': defaultdict(None, {'new_price': '89.95  EUR', 'saving': 39.96, 'old_price': '49.99  EUR'}), 'STRIPED DRESS': defaultdict(None, {'new_price': '19.95  EUR', 'saving': 6.959999999999999, 'old_price': '12.99  EUR'}), 'HALTER NECK SHIMMER THREAD DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'V-NECK TUNIC': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'DRESS WITH ZIPS': defaultdict(None, {'new_price': '25.95  EUR', 'saving': 7.960000000000001, 'old_price': '17.99  EUR'}), 'FLOUNCE DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'LONG TUNIC WITH SIDE VENTS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'FLOWING STUDIO DRESS': defaultdict(None, {'new_price': '89.95  EUR', 'saving': 39.96, 'old_price': '49.99  EUR'}), 'KNIT SWEATER WITH TAILORED HEM': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 19.960000000000004, 'old_price': '29.99  EUR'}), 'BUTTON DETAIL DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'SUEDE EFFECT DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 19.960000000000004, 'old_price': '29.99  EUR'}), 'FAUX LEATHER DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'POLKA DOT DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'CREPE SLEEVELESS DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 19.960000000000004, 'old_price': '29.99  EUR'}), 'DEVORÉ VELVET DRESS': defaultdict(None, {'new_price': '59.95  EUR', 'saving': 9.96, 'old_price': '49.99  EUR'}), 'DENIM DRESS WITH BELT': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 19.960000000000004, 'old_price': '29.99  EUR'}), 'LACE APPLIQUÉ DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 19.960000000000004, 'old_price': '29.99  EUR'}), 'JACQUARD DRESS': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 9.96, 'old_price': '19.99  EUR'}), 'PATCH PINAFORE DRESS': defaultdict(None, {'new_price': '45.95  EUR', 'saving': 19.960000000000004, 'old_price': '25.99  EUR'}), 'EYELET DRESS WITH VELVET RIBBON': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 19.960000000000004, 'old_price': '29.99  EUR'}), 'LONG LACE DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 23.960000000000004, 'old_price': '25.99  EUR'}), 'LONG PATCHWORK DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 19.960000000000004, 'old_price': '29.99  EUR'}), 'MIDI CROSSOVER DRESS': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 9.96, 'old_price': '19.99  EUR'}), 'EMBROIDERED DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'LONG CREPE DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 19.960000000000004, 'old_price': '29.99  EUR'}), 'HALTER NECK DRESS': defaultdict(None, {'new_price': '59.95  EUR', 'saving': 9.96, 'old_price': '49.99  EUR'}), 'DRESS WITH GATHERED WAIST': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 9.96, 'old_price': '19.99  EUR'}), 'GINGHAM CHECK TUNIC': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'JUMPSUIT WITH STRAPS': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 9.96, 'old_price': '19.99  EUR'}), 'DOUBLE LAYER DRESS': defaultdict(None, {'new_price': '59.95  EUR', 'saving': 9.96, 'old_price': '49.99  EUR'}), 'LACE DRESS': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 9.96, 'old_price': '19.99  EUR'}), 'MIDI PINAFORE DRESS': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 9.96, 'old_price': '19.99  EUR'}), 'LONG TUNIC': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'BANDEAU DRESS': defaultdict(None, {'new_price': '25.95  EUR', 'saving': 7.960000000000001, 'old_price': '17.99  EUR'}), 'LINEN SHIRTDRESS BELT': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'STUDIO DRESS': defaultdict(None, {'new_price': '59.95  EUR', 'saving': 9.96, 'old_price': '49.99  EUR'}), 'CHECK PINAFORE DRESS': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 9.96, 'old_price': '19.99  EUR'}), 'LONG SILK STUDIO DRESS WITH LACE': defaultdict(None, {'new_price': '99.95  EUR', 'saving': 49.96, 'old_price': '49.99  EUR'}), 'BEAD EMBROIDERED DRESS': defaultdict(None, {'new_price': '59.95  EUR', 'saving': 29.960000000000004, 'old_price': '29.99  EUR'}), 'DRESS WITH SIDE GATHERING': defaultdict(None, {'new_price': '19.95  EUR', 'saving': 6.959999999999999, 'old_price': '12.99  EUR'}), 'DRESS WITH BACK OPENING': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 11.96, 'old_price': '17.99  EUR'}), 'SCHIFFLI LACE DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 23.960000000000004, 'old_price': '25.99  EUR'}), 'SPARKLY VELVET DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 19.960000000000004, 'old_price': '29.99  EUR'}), 'STRAPPY DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'TUNIC WITH SLITS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'A-LINE PATCHWORK DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'DRESS WITH SEAM DETAILS': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 11.96, 'old_price': '17.99  EUR'}), 'COMBINATION DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'MICRO-JACQUARD DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'PINAFORE DRESS': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 9.96, 'old_price': '19.99  EUR'}), 'JACQUARD GEMSTONE DRESS': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 11.96, 'old_price': '17.99  EUR'}), 'VELVET DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'HOUNDSTOOTH PINAFORE DRESS': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 9.96, 'old_price': '19.99  EUR'}), 'KNIT DRESS': defaultdict(None, {'new_price': '17.95  EUR', 'saving': 4.959999999999999, 'old_price': '12.99  EUR'}), 'LOOSE FIT PRINTED DRESS': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 9.96, 'old_price': '19.99  EUR'}), 'LEATHER EFFECT DRESS. CUT WORK': defaultdict(None, {'new_price': '59.95  EUR', 'saving': 9.96, 'old_price': '49.99  EUR'}), 'GEOMETRIC DRESS': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 11.96, 'old_price': '17.99  EUR'}), 'LONG DRESS': defaultdict(None, {'new_price': '25.95  EUR', 'saving': 7.960000000000001, 'old_price': '17.99  EUR'}), 'RETRO PINAFORE DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'CHECK DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 19.960000000000004, 'old_price': '29.99  EUR'}), 'PRINTED SHIRT DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'PATTERNED DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 9.96, 'old_price': '39.99  EUR'}), 'DRESS WITH CHAIN NECKLINE': defaultdict(None, {'new_price': '59.95  EUR', 'saving': 29.960000000000004, 'old_price': '29.99  EUR'}), 'STAR PRINT DRESS': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 11.96, 'old_price': '17.99  EUR'}), 'DENIM DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'ROUND NECK DRESS': defaultdict(None, {'new_price': '45.95  EUR', 'saving': 19.960000000000004, 'old_price': '25.99  EUR'}), 'FLORAL PRINT DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'RUFFLE DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'SHORT DRESS': defaultdict(None, {'new_price': '25.99  EUR', 'saving': 8.0, 'old_price': '17.99  EUR'}), 'PRINTED DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'FLARED DRESS': defaultdict(None, {'new_price': '59.95  EUR', 'saving': 9.96, 'old_price': '49.99  EUR'}), 'DENIM PINAFORE DRESS': defaultdict(None, {'new_price': '45.95  EUR', 'saving': 19.960000000000004, 'old_price': '25.99  EUR'}), 'ZIP-BACK TUBE DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 19.960000000000004, 'old_price': '29.99  EUR'}), 'ASYMMETRIC DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'DRAPED DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'STRIPED JACQUARD DRESS': defaultdict(None, {'new_price': '25.95  EUR', 'saving': 7.960000000000001, 'old_price': '17.99  EUR'}), 'DRESS WITH SIDE KNOT DETAIL': defaultdict(None, {'new_price': '19.95  EUR', 'saving': 6.959999999999999, 'old_price': '12.99  EUR'}), 'OTTOMAN RIB DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'FLOWING TUNIC': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'METALLIC APPLIQUÉ TUNIC': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 9.96, 'old_price': '19.99  EUR'}), 'PATCHWORK DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'PARTY DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 19.960000000000004, 'old_price': '29.99  EUR'}), 'FRAYED MIDI DRESS': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 9.96, 'old_price': '19.99  EUR'}), 'FLORAL DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'SKATER DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 9.96, 'old_price': '39.99  EUR'}), 'DRESS WITH LOW-CUT BACK': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 9.96, 'old_price': '39.99  EUR'}), 'LONG DOUBLE LAYER DRESS': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 11.96, 'old_price': '17.99  EUR'}), 'LONG TUBE DRESS': defaultdict(None, {'new_price': '59.95  EUR', 'saving': 9.96, 'old_price': '49.99  EUR'}), 'FITTED DRESS': defaultdict(None, {'new_price': '14.95  EUR', 'saving': 4.959999999999999, 'old_price': '9.99  EUR'}), 'DRESS WITH V-NECK BACK': defaultdict(None, {'new_price': '29.95  EUR', 'saving': 11.96, 'old_price': '17.99  EUR'}), 'LONG VELVET DRESS': defaultdict(None, {'new_price': '89.95  EUR', 'saving': 39.96, 'old_price': '49.99  EUR'}), 'HALTER DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 9.960000000000004, 'old_price': '29.99  EUR'}), 'PRINTED TUNIC': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'FULL TUNIC WITH PLAITED BELT': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'STUDIO DRESS WITH LACE-UP BACK': defaultdict(None, {'new_price': '69.95  EUR', 'saving': 19.96, 'old_price': '49.99  EUR'}), 'DOTTED SWISS DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 23.960000000000004, 'old_price': '25.99  EUR'}), 'SHORT LACE DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 9.96, 'old_price': '39.99  EUR'}), 'DRESS WITH FULL SKIRT': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 19.960000000000004, 'old_price': '29.99  EUR'}), 'ASYMMETRICAL LONG DRESS': defaultdict(None, {'new_price': '17.95  EUR', 'saving': 4.959999999999999, 'old_price': '12.99  EUR'}), 'STRAIGHT CUT DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'MIDI DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'}), 'PLEATED DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 19.960000000000004, 'old_price': '29.99  EUR'}), 'LACE SKATER DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 9.96, 'old_price': '39.99  EUR'}), 'TUBE DRESS WITH STRAPPY BACK': defaultdict(None, {'new_price': '59.95  EUR', 'saving': 9.96, 'old_price': '49.99  EUR'}), 'LONG PRINTED DRESS': defaultdict(None, {'new_price': '49.95  EUR', 'saving': 9.96, 'old_price': '39.99  EUR'}), 'SHEER DRESS': defaultdict(None, {'new_price': '59.95  EUR', 'saving': 33.96000000000001, 'old_price': '25.99  EUR'}), 'A-LINE TOP': defaultdict(None, {'new_price': '59.95  EUR', 'saving': 9.96, 'old_price': '49.99  EUR'}), 'RIBBED DRESS': defaultdict(None, {'new_price': '17.95  EUR', 'saving': 4.959999999999999, 'old_price': '12.99  EUR'}), '"ESSENTIALS" DENIM PINAFORE DRESS': defaultdict(None, {'new_price': '19.95  EUR', 'saving': 6.959999999999999, 'old_price': '12.99  EUR'}), 'PRINTED JUMPSUIT DRESS': defaultdict(None, {'new_price': '39.95  EUR', 'saving': 13.960000000000004, 'old_price': '25.99  EUR'})})
这会给你一个类似的df:

                                 name    old    new  saving
0                 ZIP-BACK TUBE DRESS  49.95  29.99   19.96
1                     SEQUINNED DRESS  69.95  29.99   39.96
2    HALTER NECK SHIMMER THREAD DRESS  39.95  25.99   13.96
3              CREPE SLEEVELESS DRESS  49.95  29.99   19.96
4                   OTTOMAN RIB DRESS  39.95  25.99   13.96
5                    SHORT LACE DRESS  49.95  39.99    9.96
6                SPARKLY VELVET DRESS  49.95  29.99   19.96
7           DRESS WITH SIDE GATHERING  19.95  12.99    6.96
8        TUBE DRESS WITH STRAPPY BACK  59.95  49.99    9.96
9                        SKATER DRESS  49.95  39.99    9.96
10                        PARTY DRESS  49.95  29.99   19.96
11                 DOUBLE LAYER DRESS  29.95  17.99   11.96
12            DRESS WITH LOW-CUT BACK  49.95  39.99    9.96
13          DRESS WITH SIDE GATHERING  19.95  12.99    6.96
14                       STUDIO DRESS  79.95  49.99   29.96
15                 DOUBLE LAYER DRESS  59.95  49.99    9.96
16     STUDIO DRESS WITH LACE-UP BACK  69.95  49.99   19.96
并将数据保存到名为data.csv的csv中

要以最大的节省量加载数据和订单,请执行以下操作:

df = pd.read_csv("data.csv")


print(df.sort_values(["saving"],ascending=0))
这将产生:

                                  name    old    new  saving
134   LONG SILK STUDIO DRESS WITH LACE  99.95  49.99   49.96
1                      SEQUINNED DRESS  69.95  29.99   39.96
137                  LONG VELVET DRESS  89.95  49.99   39.96
71                FLOWING STUDIO DRESS  89.95  49.99   39.96
33                  LONG CROCHET DRESS  89.95  49.99   39.96
116                        SHEER DRESS  59.95  25.99   33.96
85           DRESS WITH CHAIN NECKLINE  59.95  29.99   29.96
132             BEAD EMBROIDERED DRESS  59.95  29.99   29.96
14                        STUDIO DRESS  79.95  49.99   29.96
......................................................
要添加一列,该列应显示保存百分比:

df["precent_saving"] = (df["old"] - df["new"]) / df["old"] * 100
print(df)
输出:

ZIP-BACK TUBE DRESS
Old price  49.95  EUR
New price 29.99  EUR
SEQUINNED DRESS
Old price  69.95  EUR
New price 29.99  EUR
HALTER NECK SHIMMER THREAD DRESS
Old price  39.95  EUR
New price 25.99  EUR
CREPE SLEEVELESS DRESS
Old price  49.95  EUR
New price 29.99  EUR
OTTOMAN RIB DRESS
Old price  39.95  EUR
New price 25.99  EUR
SHORT LACE DRESS
Old price  49.95  EUR
New price 39.99  EUR
SPARKLY VELVET DRESS
Old price  49.95  EUR
New price 29.99  EUR
DRESS WITH SIDE GATHERING
Old price  19.95  EUR
New price 12.99  EUR
TUBE DRESS WITH STRAPPY BACK
Old price  59.95  EUR
New price 49.99  EUR
SKATER DRESS
Old price  49.95  EUR
New price 39.99  EUR
PARTY DRESS
Old price  49.95  EUR
New price 29.99  EUR
DOUBLE LAYER DRESS
........................
                               name    old    new  saving  precent_saving
0                 ZIP-BACK TUBE DRESS  49.95  29.99   19.96       39.959960
1                     SEQUINNED DRESS  69.95  29.99   39.96       57.126519
2    HALTER NECK SHIMMER THREAD DRESS  39.95  25.99   13.96       34.943680
3              CREPE SLEEVELESS DRESS  49.95  29.99   19.96       39.959960
4                   OTTOMAN RIB DRESS  39.95  25.99   13.96       34.943680
5                    SHORT LACE DRESS  49.95  39.99    9.96       19.939940
6                SPARKLY VELVET DRESS  49.95  29.99   19.96       39.959960
7           DRESS WITH SIDE GATHERING  19.95  12.99    6.96       34.887218
8        TUBE DRESS WITH STRAPPY BACK  59.95  49.99    9.96       16.613845
9                        SKATER DRESS  49.95  39.99    9.96       19.939940
10                        PARTY DRESS  49.95  29.99   19.96       39.959960
11                 DOUBLE LAYER DRESS  29.95  17.99   11.96       39.933222

请张贴你正在处理的html代码。你确定你能刮去那页吗?我得到urllib.error.HTTPError:HTTP错误403:禁止