Note that there are some explanatory texts on larger screens.

plurals
  1. POPython: how to insert a series of data into database and display them all
    primarykey
    data
    text
    <p>i am try to using python with database to display a series of information. however, my output only display the last column. i know i am not express my means very clearly. so, i put my code and output as follow: now the output show:</p> <pre><code> $ python pricewatch.py Harvey Norman Site Search iPad 2 Wi-Fi 16GB Black iPad 2 Wi-Fi 16GB iPad mini Wi-Fi + Cellular 32GB iPad mini Wi-Fi 16GB iPad mini Wi-Fi + Cellular 64GB iPad Wi-Fi 64GB with Retina Display iPad Wi-Fi 32GB with Retina Display iPad 2 Wi-Fi 16GB White iPad 2 Wi-Fi + 3G 16GB iPad Wi-Fi + Cellular 32GB with Retina Display iPad mini Wi-Fi + Cellular 16GB $357 $697 $756 $647 $395 $545 $777 $487 (8, u'iPad mini Wi-Fi + Cellular 16GB', u'Harvey Norman Site Search', u'$487') </code></pre> <p>//as you can see, it only show the last one my code is </p> <pre><code>url="http://m.harveynorman.com.au/computers/tablets-readers/ipads" page=urllib2.urlopen(url) soup = BeautifulSoup(page.read()) sitename=soup.find('label',{'for':'search'}) print sitename.renderContents() productname=soup.findAll('strong',{'class':'name fn'}) for eachproductname in productname: print eachproductname.renderContents() productprice=soup.findAll('span',{'class':'price'}) for eachproductprice in productprice: print eachproductprice.renderContents().replace("&lt;span&gt;","").replace("&lt;/span&gt;","") conn =sqlite3.connect('pricewatch.db') c = conn.cursor() c.execute("CREATE TABLE if not exists table1 (id integer, name text, store text, price real)") eachname = eachproductname.renderContents() eachprice = eachproductprice.renderContents().replace("&lt;span&gt;","").replace("&lt;/span&gt;","") sitename = sitename.renderContents() assignnumber = randint(1,30) #issue here,want to assign a series of number by the scriptself data = [(assignnumber,eachname,sitename,eachprice), ] c.executemany('INSERT INTO table1 VALUES (?,?,?,?)',data) #output for row in c.execute('select * from table1'): print row </code></pre> <p>now, the output i want from the database is like (1,ipadXX,HN,$199) (2,ipad xx, NH, $200) .....</p> <p>hope anyone can give the hints or edit my script.</p> <p>regards yuhang</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload