title: Python: Save the previously scraped data in database (already created)
body: <p>I have done the scraping with Selenium correctly and the results are printed perfectly. I don't know how to save them in a database I have already created the tables and fields with Sqlite. In general I know how to save the data in a database, but I don't know how to save the scraping data. What I don't know is how to write the code to save the scraping data.</p>
  <p>Now I would just like to add the scraped data into the database and save. The database table name is TableExample1. The fields are: ID, Product_NameDB, Product_DescriptionDB, VendorDB, PriceDB.</p>
  <p>I have 2 problems</p>
  <ol>
  <li>The text that is saved in the database like this: [&lt;selenium.webdriver.firefox.webelement.FirefoxWebElement (session = &quot;226bc9f3</li>
  <li>Only one (1) row is added to the database. Instead, dozens or hundreds of them should be added (each like this: Product_Name, Product_Description, Vendor, Price), depending on the scraped data.</li>
  </ol>
  <p>The Python code with the data printed by the scraping is as follows:</p>
  <pre><code>#Name of the scraped data 
  Product_Name = (driver.find_element_by_class_name (&quot;tablet-desktop-only&quot;). Text)
  Product_Description = (driver.find_element_by_class_name (&quot;h-text-left&quot;). Text)
  Vendor = (driver.find_element_by_class_name (&quot;in-vendor&quot;). Text)
  Price = (driver.find_element_by_class_name (&quot;h-text-center&quot;). Text)
  
  for seq in Product_Name + Product_Description + Vendor + Price:
      print(seq.text)
  </code></pre>
  <p><strong>UPDATE N.1
  Current code, following <a href="https://stackoverflow.com/users/6656050/jeremy-kahan">&quot;Jeremy Kahan&quot;</a>'s answers to this question</strong><br />
  and in <a href="https://stackoverflow.com/questions/68093571/scrape-many-products-with-the-same-name-html-i-can-only-scrape-one-not-all-of">THIS</a> (it is different, I asked to print in the console all the results of the scraping and not just 1)</p>
  <p>This is the current most stable and functioning code. Scraping works fine, but that Num_Groups and for i in range (Num_Groups) you suggested in the other question, print only one group, not all.</p>
  <p>I still have the same 2 problems</p>
  <ol>
  <li><p>The text that is saved in the database like this: [&lt;selenium.webdriver.firefox.webelement.FirefoxWebElement (session = &quot;226bc9f3</p>
  </li>
  <li><p>Only one (1) row is added to the database. Instead, dozens or hundreds of them should be added (each like this: Product_Name, Product_Description, Vendor, Price), depending on the scraped data.</p>
  <pre><code> import sqlite3
   from datetime import datetime 
  
   #SCRAPING
   Product_Name=driver.find_elements_by_class_name(&quot;tablet-desktop-only&quot;)
   Product_Description=driver.find_elements_by_class_name(&quot;h-text-left&quot;)
   Vendor=driver.find_elements_by_class_name(&quot;in-match&quot;)
   Price=driver.find_elements_by_class_name(&quot;h-text-center&quot;)
  
  
   # How do I print the other data always with the same html name?
   # This is one row data. This is the code you wrote me in the  
   # other question. Print only one group. What to write to print 
   # all groups?  
   Num_Groups = min(len(Product_Name),len(Product_Description),len(Vendor), len(Price))
  
   for i in range(Num_Groups):    
       print(Product_Name[i].text)
       print(Product_Description[i].text)
       print(Vendor[i].text)
       print(Price[i].text)
  
  
   #INSERT DATA IN DATABASE
   con = sqlite3.connect('/home/mypc/Desktop/aaaaa/Database.db')
   cursor = con.cursor()
  
   ID=datetime.today().strftime('%Y%m%d%H%M%S')
   Values =   f&quot;VALUES({ID},'{Product_Name}','{Product_Description}','{Vendor}','{Price}')&quot;
   sqlite_insert_query = 'INSERT INTO TableExample1 (ID, Product_Name, Product_Description, Vendor, Price)' + Values
  
   count = cursor.execute(sqlite_insert_query)
   con.commit()
   print(&quot;Record inserted successfully &quot;, cursor.rowcount)
   cursor.close()
  </code></pre>
  </li>
  </ol>
  <p><strong>2° UPLOAD (final?)</strong>
  PROBLEM: found 12 groups, Record inserted successfully 1, Added a total of 1 records How do I get 12 staves inserted in the database?</p>
  <pre><code>Num_Groups = min(len(Product_Name),len(Product_Description),len(Vendor), len(Price))
  
  records_added = 0
  
   for i in range(Num_Groups):    
       print(Product_Name[i].text)
       print(Product_Description[i].text)
       print(Vendor[i].text)
       print(Price[i].text)
  
  
  con = sqlite3.connect('/home/mypc/Scrivania/aaaa/Database.db')
  cursor = con.cursor()
  
  Values = f&quot; VALUES ('{Product_Name[i].text}','{Product_Description[i].text}','{Vendor[i].text}','{Price[i].text}')&quot;
  sqlite_insert_query = 'INSERT INTO TableExample1 (Product_Name, Product_Description, Vendor, Price)' + Values
  
  print(&quot;Qui, all'interno del ciclo, eseguiresti&quot; + sqlite_insert_query)
  
  count = cursor.execute(sqlite_insert_query)
  con.commit()
  print(&quot;Record inserted successfully &quot;, cursor.rowcount)
  records_added = records_added + 1
  cursor.close()
  
  print(&quot;&quot;)
  print(f'Added a total of {records_added} records')
  print(f&quot;found {Num_Groups} groups&quot;)  # should be more than 1
  </code></pre>