Python Forum
Writing to right spot in CSV and I'm a noob
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Writing to right spot in CSV and I'm a noob
#1
DISCLAIMER: I'm new to python and programming in general(only been coding for a couple days.go.easy.on.me)


I'm trying to write a code that will scrape my website and retrieve [Product Name, Product Price] and write it to a csv file.
when I write it to the csv file the information doesn't go where I want it to go:
[Image: CSVMESSUP_zpsq3vxqisz.png]

I'm not getting any errors thank god Dance

I was wondering if someone would be so kind as to review my code and tell me how to make it work the way I'd like.

#source variables
source = requests.get('https://www.shopshiptrack.com/index.php?route=product/catalog&limit=100').text

soup = BeautifulSoup(source, 'lxml')

#lists
product_lst = []
price_lst = []


#csv creation
with open('list.csv', 'w', newline="") as csv_file:
    csv_writer = writer(csv_file)
    headers = ['Name', 'Price']
    csv_writer.writerow(headers)
# code
    for products_section in soup.find_all('div', class_='name'):
        product_names = products_section.a.text
        product_lst.append(product_names)
    csv_writer.writerow(product_lst)


    for products_price in soup.find_all('span', class_='price-normal'):
        specific_price = products_price.text
        price_lst.append(specific_price)
    csv_writer.writerow(price_lst)
Reply


Messages In This Thread
Writing to right spot in CSV and I'm a noob - by faizon - Feb-15-2019, 08:51 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020