擅长:python、mysql、java
<p>您需要.text属性,您也可以在列表理解期间提取该属性。然后list/zip在末尾显示名称/价格的元组列表</p>
<pre><code>import requests
from bs4 import BeautifulSoup
url = 'https://www.prohockeylife.com/collections/senior-hockey-sticks'
headers = {'user-agent': 'Mozilla/5.0'}
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')
stick_names = [item.text.strip() for item in soup.find_all(class_='product-title')]
stick_prices = [item.text.strip() for item in soup.find_all(class_='regular-product')]
print(list(zip(stick_names, stick_prices)))
</code></pre>