<p>这将为您提供在列表中查找的所需输出:</p>
<pre><code>import requests
import bs4
r = requests.get("https://www.viperprint.pl/produkt/arkusze-plano/AP01")
soup = bs4.BeautifulSoup(r.content, 'html.parser')
elems = soup.find_all('a', {'class': 'tabela_cenowa eprint_product_link add_to_cart_link'})
hehes = soup.find_all('a', {'id': 'dLabel'})
results = []
nazwa_list = []
qty_value = None
for elem, hehe in zip(elems, hehes):
nazwa = hehe.get('title')
if qty_value == None:
qty_value = elem.attrs.get('data-qty')
if nazwa != None:
nazwa_list.append(nazwa)
nazwa_list.append(qty_value)
results = nazwa_list
</code></pre>
<p>输出:</p>
<pre><code>In [1]: print (results)
Out [1]: ['Arkusze PLANO', 'A1+ (880 x 630 mm)', 'Dwustronnie kolorowe (4+4 CMYK)', 'Kreda błysk 130g', 'Bez uszlachetniania (0+0)', '100']
</code></pre>
<p>但是你说你想把它放到csv里。所以你可以把它放在一张桌子上,如果你想的话,也可以这样做</p>
<pre><code>import requests
import bs4
import pandas as pd
r = requests.get("https://www.viperprint.pl/produkt/arkusze-plano/AP01")
soup = bs4.BeautifulSoup(r.content, 'html.parser')
elems = soup.find_all('a', {'class': 'tabela_cenowa eprint_product_link add_to_cart_link'})
hehes = soup.find_all('a', {'id': 'dLabel'})
results = pd.DataFrame()
for elem, hehe in zip(elems, hehes):
nazwa = hehe.get('title')
qty = elem.attrs.get('data-qty')
temp_df = pd.DataFrame([[nazwa, qty]], columns = ['title', 'qty'])
results = results.append(temp_df)
</code></pre>