I was trying to a get the list of colors from wikipedia using
BeautifulSoup an d
requests library. I am getting the result but no matter how hard i try couldn’t get the result in proper order so that i can write into a file which in turn will be used in another program. So, please help. Below is the code.
# coding: utf-8 from bs4 import BeautifulSoup import requests r = requests.get('https://en.wikipedia.org/wiki/List_of_colors_(compact)') soup = BeautifulSoup(r.text, 'html.parser') for i in soup.find_all('p'): print (i.text, i.get('title'))
Result from the above code (sample):
𝗛𝗦𝗩 (79° 42% 89%) 𝗥𝗚𝗕 (197 227 132) 𝗛𝗘𝗫 #C5E384 Yellow-green (Crayola) None 𝗛𝗦𝗩 (36° 62% 89%) 𝗥𝗚𝗕 (227 171 87) 𝗛𝗘𝗫 #E3AB57 Sunray None 𝗛𝗦𝗩 (30° 25% 100%) 𝗥𝗚𝗕 (255 223 191) 𝗛𝗘𝗫 #FFDFBF Very pale orange None
Desired result (includes only RGB values and the name in a row separated by space):
197 227 132 Yellow-green (Crayola) 227 171 87 Sunray 255 223 191 Very pale orange