python for loop variable and saving to csv
<p>This is a 2 part question:</p>

<p>I have tested my code and it is working but the final piece I cannot figure out.
I have been able to print this out and it works but when I try and save it to a file I am getting errors.  After I run the for loop and print the output looks like this (which may not show correctly on this site but in essence it is vertical):</p>

<pre><code>42322

Signal Lighting
Brackets &amp; Grommets
Vertical Mount MicroNova® Dot LED License  [...]
42332

Signal Lighting
Brackets &amp; Grommets
Vertical Mount MicroNova® Dot LED License  [...]
43022

Signal Lighting
Brackets &amp; Grommets
Universal Steel Offset License Plate Brack [...]
43022-3

Signal Lighting
Brackets &amp; Grommets
Universal Steel Offset License Plate Brack [...]
</code></pre>

<p>This is what I am hoping it will look like in a csv file (turning the vertical horizontal):</p>

<pre><code>42322   Signal Lighting Brackets &amp; Grommets Vertical Mount MicroNova® Dot LED License  [...]
42332   Signal Lighting Brackets &amp; Grommets Vertical Mount MicroNova® Dot LED License  [...]
43022   Signal Lighting Brackets &amp; Grommets Universal Steel Offset License Plate Brack [...]
43022-3 Signal Lighting Brackets &amp; Grommets Universal Steel Offset License Plate Brack [...]
</code></pre>

<p>Here is my code to print:</p>

<pre><code>import urllib
import urllib.request
from bs4 import BeautifulSoup
import os
import csv

f = open('gropn1.csv')
csv_f = csv.reader(f)

for row in csv_f:

    theurl="http://www.grote.com/?s="+row[1] + "&amp;q1=1"
    thepage = urllib.request.urlopen(theurl)
    soup = BeautifulSoup(thepage,"html.parser")

    for partno in soup.find_all('h2',{"class":"single-product-number"}):
        print(partno.text)

    for link in soup.find('ul',{"class":"breadcrumbs"}).findAll('a'):
        print(link.text)
f.close()
</code></pre>

<p>To save it to a file I have tried this - changing from the first for partno loop down:</p>

<pre><code>    partno = soup.find_all('h2',{"class":"single-product-number"})
    link = soup.find('ul',{"class":"breadcrumbs"}).findAll('a')

file = open(os.path.expanduser("grotes.csv"),"wb")
file.write(bytes(partno, encoding="ascii",errors='ignore'))
file.write(bytes(link, encoding="ascii",errors='ignore'))

f.close
</code></pre>

<p>I have tried other things but I think the above is as close as I have come to making it work, which doesn't include trying to use the zip function - here is the error I am getting:</p>

<pre><code>Traceback (most recent call last):
  File "C:/Users/PPluck/Downloads/grotestart3.py", line 24, in &lt;module&gt;
    file.write(bytes(partno, encoding="ascii",errors='ignore'))
TypeError: encoding or errors without a string argument
</code></pre>

<p>Sorry for the crazy lengthy question.</p>