Не могу создать папку через команду с моим py-файлом? - PullRequest
0 голосов
/ 17 февраля 2019

Я только что попытался сделать файл Beautifulsoup для aliexpress, хотя файл работает по команде правильно, я не смог создать папку.

Можете ли вы помочь мне?

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()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...