Click here to Skip to main content
15,845,681 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Sir, I'm using Python to scarp several data from the website and the data should be added to the list box.
I'm using requests module and beautiful soup to pull out contents from the website. Python version 3.5.1

Python
for var in soup.find_all('div',class_="row"):
     var1 = var.text
     list1.insert(END,var1)


here soup = BeautifulSoup(Content pulled using request)

when printing the var1 I do get the desired output like this,

Dairy Milk
Dairy Milk is the most selling chocolate brand in India and is the most popular one among people of all ages. It is manufactured by Cadbury India, an Indian subsidiary of Cadbury, which is a British multinational company. Fruit and Nut, Crackle and Roast Almond are popular variants of Dairy Milk Chocolate.


But when I try to add this in a list box using an insert statement the list box treats the content in the var1 as a single object so I get my output in a single very very long horizontal line.

Kindly help me with this sir
Thank you for your time sir

What I have tried:

I thought since the loop is iterating after every insert statement I added a new line like this,
Python
for var in soup.find_all('div',class_="row"):
     var1 = var.text
     list1.insert(END,var1)
     list1.insert(END,"\n")
but no use since the whole stuff is inserted first and then it goes for a new line.

Used in and if like this ,
Python
if "\n" in var1:
   list1.insert(END,"\n")


but no use to.
I referred in the internet for "Python Tkinter - inserting data into a list box as it is" but got irrelevant results.

Kindly help me with this sir
Thank you for your time sir
Posted
Comments
Richard MacCutchan 8-May-16 2:55am    
You need to split the string into its separate parts, and then add each substring in turn.
[no name] 9-May-16 13:53pm    
Thank you sir for your kind help. I made it worked.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900