Python Forum

Full Version: how to insert list into database
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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()
X = "HELLO"
Y = "RAJESH"
list = [X,Y]

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