Try to search your question here, if you can't find : Ask Any Question Now ?

Not able to arrange results of web parsing in proper order

HomeCategory: stackoverflowNot able to arrange results of web parsing in proper order
Avatarjohn asked 1 month ago

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
1 Answers
Best Answer
AvatarMikhail answered 1 month ago
Your Answer

18 + 16 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com