【发布时间】:2020-06-10 05:52:47
【问题描述】:
早上好,我正在尝试从网站https://shop.fattoriaterranova.it/it/14-marmellate 提取每个果酱罐的价格和成本。
这是我的代码:
#import modules
import urllib.request, urllib.parse, urllib.error
from urllib import request
from bs4 import BeautifulSoup
import ssl
# Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
#BeautifulSoup & url
url = 'https://shop.fattoriaterranova.it/it/14-marmellate'
html = request.urlopen(url, context=ctx).read()
soup = BeautifulSoup(html,"html.parser")
results = soup.find(id='product_list')
products = results.find_all('ul', class_='product_list grid row')
print(products)
for product in products:
price_elem = product.find('span', class_='price product-price')
prod_elem = product.find('a', class_='product-name')
if None in (price_elem, prod_elm):
continue
print(price_elem.strip())
print(prod_elem.strip())
print(results.strip())
我得到的输出是
[ ]
我做错了什么?
谢谢
【问题讨论】:
标签: python-3.x parsing html-parsing