Python Forum
how to insert list into database
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to insert list into database
#1
I am storing <p> tag data into list. When i apply insert query then last line of the list stored in the database.
I want to store all data in database that is available in link.
Below is the code of adding <p> tags data into list:

 content_html_container=soup_loop.find('div', class_="template__main")
    content=content_html_container.find_all('div',class_="story__content")

    for list_p in content:
        p=list_p.find_all('p')
        for li in p:
              p=li.text
#              print(p)
              p_list.append(p)
below is the database query:

 news_detail_query="INSERT INTO news_detail (`date`, heading, content, id_authors, id_categories) VALUES (%s, %s, %s, %s, %s)"
    insert_news=(timestamp,heading,p,authors_id,categories_id)
    result  = cursor.execute(news_detail_query, insert_news)
    cnx.commit()
Reply
#2
see: https://stackoverflow.com/questions/3070...base-table
Reply
#3
X = "HELLO"
Y = "RAJESH"
list = [X,Y]

INSERT INTO table VALUES ('%s') %s list
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  store all variable values into list and insert to sql_summary table mg24 3 1,095 Sep-28-2022, 09:13 AM
Last Post: Larz60+
  Populate Dropdown list from Database TommyAutomagically 4 4,347 Nov-02-2021, 05:23 PM
Last Post: ndc85430
  openpyxl insert list with formulas Irv1n 1 1,516 Sep-16-2021, 08:10 AM
Last Post: Irv1n
Photo Insert 0 values in database saljuaid 4 2,524 Nov-08-2020, 12:09 PM
Last Post: saljuaid
  Datas are not insert into database aravinth 1 2,152 Dec-21-2019, 04:17 PM
Last Post: buran
  Create application that will take information from database and insert into PDF sorrelsj 1 2,042 Aug-19-2019, 10:08 PM
Last Post: Gribouillis
  Store a python list of lists in a database to use for searches later on klllmmm 3 3,008 Jun-20-2019, 07:54 AM
Last Post: buran
  Creating a persistent list/database Trinx 1 2,223 Feb-27-2019, 06:20 PM
Last Post: ichabod801
  Insert list in particular column! Help! vndywarhol 0 2,455 Sep-17-2018, 11:14 PM
Last Post: vndywarhol
  insert list into sqlite3 mepyyeti 3 13,597 Jan-15-2018, 06:35 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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