2

I've just tried to make a beautifulsoup file for aliexpress, even though the file runs on command properly, I couldn't create a folder.

Can you please help me?

from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup

my_url = 'https://www.aliexpress.com/category/200003482/dresses.html?spm=2114.11010108.101.3.650c649b3Cw8J9&g=y'

#opening up connection, grabbing the page
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()

# html parsing
page_soup = soup(page_html, 'html.parser')

#grabs each product
containers = page_soup.findAll('div',{'class':'item'})

filename = 'product.csv'
f = open(filename, 'w')

headers = 'product_name, item_price, store_name\n'

f.write(headers)

contain = containers[0]
container = containers[0]


for container in containers:
    product_name = container.h3.a.text

    product_container = container.findAll('span',{'class':'price price-m'})
    price_container = product_container[0].findAll('span',{'class':'value'})
    item_price = price_container[0].text

    store_container = container.findAll('div',{'class':'info-more'})
    store_container[0].findAll('div',{'class':'store-name util-clearfix'})
    name_container = store_container[0].findAll('div',{'class':'store-name util-clearfix'})
    store_name = name_container[0].a.text


    print('product_name: ' + product_name)

    print('item_price: ' +  item_price)

    print('store_name: ' +  store_name)

    f.write(product_name + ',' + item_price + ',' store_name + '\n')

f.close()
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Eren Han
  • 321
  • 3
  • 10

0 Answers0