Python 2.7 Python:逐个保存参数和产品

Python 2.7 Python:逐个保存参数和产品,python-2.7,beautifulsoup,Python 2.7,Beautifulsoup,我正在编写一个程序,获取产品名称、it参数,并暂时将其保存到文本文件中。页面是我写的: `url = "http://www.euro.com.pl/pralki,strona-1.bhtml" source_code = requests.get(url) plain_text = source_code.text soup = BeautifulSoup(plain_text, "html.parser") for product in soup.find_all('div', {'clas

我正在编写一个程序,获取产品名称、it参数,并暂时将其保存到文本文件中。页面是我写的:

`url = "http://www.euro.com.pl/pralki,strona-1.bhtml"
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, "html.parser")
for product in soup.find_all('div', {'class': 'product-main'}):
    for prod in soup.find_all('h2', {'class': 'product-name'}):
        temp.extend(prod.stripped_strings)
        for param in soup.find_all('div', {'span': 'attribute-value'}):
            temp.extend(param.stripped_strings)`
但它给了我一个超过200k行的文本文件!无法确定如何从一开始就修复或写入它。

由此:

>>> len(soup.find_all('div', {'class': 'product-main'}))
30
>>> len(soup.find_all('h2', {'class': 'product-name'}))
30
我的结论是有30个
产品
实例和30个
产品
实例

temp.extend(prod.stripped_strings)

执行900次。根据您对问题的描述,我认为您希望执行30次。

您到底想要什么?你有什么问题?我只是想把产品名称和它的参数从网页上保存到一个文件中。不是这样吗?正如我所说,在把结果放入文本文件后,它给了我超过200000行,这是不可接受的,因为当你看这个网站时,页面上只有30个产品,每个都有4-5个参数。好的,现在我知道我做错了什么,但仍然不知道如何正确地做。