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
  • 36,867
  • 50
  • 163
  • 268
Eren Han
  • 101
  • 1
  • 9
  • 1
    Can you please describe the problem a bit more? – Satya Feb 17 '19 at 16:05
  • 2
    Indeed, from the code it is not clear to me where the problem occurs. In general, `os.makedirs` makes folders. – jolvi Feb 17 '19 at 16:09
  • Check [this post](https://stackoverflow.com/questions/1274405/how-to-create-new-folder) out. – SIM Feb 17 '19 at 16:10
  • When I run the file in command prompter I can take the list properly, every products information comes clearly but when I go to path, there is no products.csv file. – Eren Han Feb 17 '19 at 16:28
  • do you look at the file after process has terminated or while it is still running? – RichieK Feb 17 '19 at 16:46
  • C:\Users\eren>where product.csv INFO: Could not find files for the given pattern(s). – Eren Han Feb 17 '19 at 16:55
  • issue resolved with f.write("%s,%s,%s\n" %( product_name, item_price, store_name)) – Eren Han Feb 20 '19 at 20:56

0 Answers0