Форум сайта python.su
Подскажите, пожалуйста.
Со страниц сайта выделил часть кода html создающий таблицу цветов с подписями.
Мне нужно из этой таблицы прочитать код цвета, он в 16-ричном формате, и его подпись.
Создать картинку размером 512х512 пикс и сохранить её в формате tga, дав название из подписи цвета.
Может есть готовое решение данной задачи?
Вот часть кода такой таблицы.
<table border="0" width="100%"> <tbody> <tr> <td width="8%" height="50" bgcolor="#C2C4AF"></td> <td width="8%" height="50" bgcolor="#B7B6A2"></td> <td width="8%" height="50" bgcolor=""></td> <td width="8%" height="50" bgcolor="#FAF0E7"></td> </tr> <tr> <td width="8%">NCS S 1502-Y</td> <td width="8%">NCS S 2002-Y</td> <td width="8%"> </td> <td width="8%">NCS S 0502-R</td> </tr> <tr> <td width="8%" height="50" bgcolor="#B6B5A1"></td> <td width="8%" height="50" bgcolor="#B9B4A1"></td> <td width="8%" height="50" bgcolor="#DBD9C4"></td> <td width="8%" height="50" bgcolor="#E2D9D2"></td> </tr> <tr> <td width="8%">NCS S 1502-Y50R</td> <td width="8%">NCS S 2002-Y50R</td> <td width="8%">NCS S 1002-Y</td> <td width="8%">NCS S 1002-R</td> </tr> <tr> <td width="8%" height="50" bgcolor="#C6C2B9"></td> <td width="8%" height="50" bgcolor="#B5B0AA"></td> <td width="8%" height="50" bgcolor="#C9C8B4"></td> <td width="8%" height="50" bgcolor="#CAC3B9"></td> </tr> <tr> <td width="8%">NCS S 1502-R</td> <td width="8%">NCS S 2002-R</td> <td width="8%">NCS S 1502-Y</td> <td width="8%">NCS S 1502-R</td> </tr> <tr> <td width="8%" height="50" bgcolor="#C5C4C2"></td> <td width="8%" height="50" bgcolor="#B3B3B3"></td> <td width="8%" height="50" bgcolor="#B5B7A2"></td> <td width="8%" height="50" bgcolor="#B4B0A7"></td> </tr> <tr> <td width="8%">NCS S 1502-R50B</td> <td width="8%">NCS S 2002-R50B</td> <td width="8%">NCS S 2002-Y</td> <td width="8%">NCS S 2002-R</td> </tr> <tr> <td width="8%" height="50" bgcolor="#BCC5C2"></td> <td width="8%" height="50" bgcolor="#ACB2AE"></td> <td width="8%" height="50" bgcolor="#A3A58F"></td> <td width="8%" height="50" bgcolor="#AAA59F"></td> </tr> <tr> <td width="8%">NCS S 1502-B</td> <td width="8%">NCS S 2002-B</td> <td width="8%">NCS S 2502-Y</td> <td width="8%">NCS S 2502-R</td> </tr> <tr> <td width="8%" height="50" bgcolor="#C0C7C0"></td> <td width="8%" height="50" bgcolor="#AFB6AF"></td> <td width="8%" height="50" bgcolor="#868775"></td> <td width="8%" height="50" bgcolor="#86837A"></td> </tr> <tr> <td width="8%">NCS S 1502-B50G</td> <td width="8%">NCS S 2002-B50G</td> <td width="8%">NCS S 2502-Y</td> <td width="8%">NCS S 2502-R</td> </tr> <tr> <td width="8%" height="50" bgcolor="#BDC5BA"></td> <td width="8%" height="50" bgcolor="#AEB4AA"></td> <td width="8%" height="50" bgcolor="#858875"></td> <td width="8%" height="50" bgcolor="#88857C"></td> </tr> <tr> <td width="8%">NCS S 1502-G</td> <td width="8%">NCS S 2002-G</td> <td width="8%">NCS S 3502-Y</td> <td width="8%">NCS S 3502-R</td> </tr> <tr> <td width="8%" height="50" bgcolor="#C2C7B6"></td> <td width="8%" height="50" bgcolor="#B4B6A9"></td> <td width="8%" height="50" bgcolor="#6A6D5A"></td> <td width="8%" height="50" bgcolor="#6C6962"></td> </tr> <tr> <td width="8%">NCS S 1502-G50Y</td> <td width="8%">NCS S 2002-G50Y</td> <td width="8%">NCS S 4502-Y</td> <td width="8%">NCS S 4502-R</td> </tr> <tr> <td width="8%" height="50" bgcolor=""></td> <td width="8%" height="50" bgcolor=""></td> <td width="8%" height="50" bgcolor="#4E5140"></td> <td width="8%" height="50" bgcolor="#515149"></td> </tr> <tr> <td width="8%"></td> <td width="8%"></td> <td width="8%">NCS S 5502-Y</td> <td width="8%">NCS S 5502-R</td> </tr> <tr> <td width="8%" height="50" bgcolor=""></td> <td width="8%" height="50" bgcolor=""></td> <td width="8%" height="50" bgcolor="#363928"></td> <td width="8%" height="50" bgcolor="#363428"></td> </tr> <tr> <td width="8%"></td> <td width="8%"></td> <td width="8%">NCS S 6502-Y</td> <td width="8%">NCS S 6502-R</td> </tr> <tr> <td width="8%" height="50" bgcolor=""></td> <td width="8%" height="50" bgcolor=""></td> <td width="8%" height="50" bgcolor="#171A07"></td> <td width="8%" height="50" bgcolor="#1A180C"></td> </tr> <tr> <td width="8%"></td> <td width="8%"></td> <td width="8%">NCS S 7502-Y</td> <td width="8%">NCS S 7502-R</td> </tr> </tbody> </table>
Офлайн
tmp = """<tr> <td width="8%" height="50" bgcolor="#C2C4AF"></td> <td width="8%" height="50" bgcolor="#B7B6A2"></td> <td width="8%" height="50" bgcolor=""></td> <td width="8%" height="50" bgcolor="#FAF0E7"></td> </tr> <tr> <td width="8%">NCS S 1502-Y</td> <td width="8%">NCS S 2002-Y</td> <td width="8%"> </td> <td width="8%">NCS S 0502-R</td> </tr> <tr> <td width="8%" height="50" bgcolor="#B6B5A1"></td> <td width="8%" height="50" bgcolor="#B9B4A1"></td> <td width="8%" height="50" bgcolor="#DBD9C4"></td> <td width="8%" height="50" bgcolor="#E2D9D2"></td> </tr> <tr> <td width="8%">NCS S 1502-Y50R</td> <td width="8%">NCS S 2002-Y50R</td> <td width="8%">NCS S 1002-Y</td> <td width="8%">NCS S 1002-R</td> </tr> <tr> <td width="8%" height="50" bgcolor="#C6C2B9"></td> <td width="8%" height="50" bgcolor="#B5B0AA"></td> <td width="8%" height="50" bgcolor="#C9C8B4"></td> <td width="8%" height="50" bgcolor="#CAC3B9"></td> </tr> <tr> <td width="8%">NCS S 1502-R</td> <td width="8%">NCS S 2002-R</td> <td width="8%">NCS S 1502-Y</td> <td width="8%">NCS S 1502-R</td> </tr> <tr> <td width="8%" height="50" bgcolor="#C5C4C2"></td> <td width="8%" height="50" bgcolor="#B3B3B3"></td> <td width="8%" height="50" bgcolor="#B5B7A2"></td> <td width="8%" height="50" bgcolor="#B4B0A7"></td> </tr> <tr> <td width="8%">NCS S 1502-R50B</td> <td width="8%">NCS S 2002-R50B</td> <td width="8%">NCS S 2002-Y</td> <td width="8%">NCS S 2002-R</td> </tr> <tr> <td width="8%" height="50" bgcolor="#BCC5C2"></td> <td width="8%" height="50" bgcolor="#ACB2AE"></td> <td width="8%" height="50" bgcolor="#A3A58F"></td> <td width="8%" height="50" bgcolor="#AAA59F"></td> </tr> <tr> <td width="8%">NCS S 1502-B</td> <td width="8%">NCS S 2002-B</td> <td width="8%">NCS S 2502-Y</td> <td width="8%">NCS S 2502-R</td> </tr> <tr> <td width="8%" height="50" bgcolor="#C0C7C0"></td> <td width="8%" height="50" bgcolor="#AFB6AF"></td> <td width="8%" height="50" bgcolor="#868775"></td> <td width="8%" height="50" bgcolor="#86837A"></td> </tr> <tr> <td width="8%">NCS S 1502-B50G</td> <td width="8%">NCS S 2002-B50G</td> <td width="8%">NCS S 2502-Y</td> <td width="8%">NCS S 2502-R</td> </tr> <tr> <td width="8%" height="50" bgcolor="#BDC5BA"></td> <td width="8%" height="50" bgcolor="#AEB4AA"></td> <td width="8%" height="50" bgcolor="#858875"></td> <td width="8%" height="50" bgcolor="#88857C"></td> </tr> <tr> <td width="8%">NCS S 1502-G</td> <td width="8%">NCS S 2002-G</td> <td width="8%">NCS S 3502-Y</td> <td width="8%">NCS S 3502-R</td> </tr> <tr> <td width="8%" height="50" bgcolor="#C2C7B6"></td> <td width="8%" height="50" bgcolor="#B4B6A9"></td> <td width="8%" height="50" bgcolor="#6A6D5A"></td> <td width="8%" height="50" bgcolor="#6C6962"></td> </tr> <tr> <td width="8%">NCS S 1502-G50Y</td> <td width="8%">NCS S 2002-G50Y</td> <td width="8%">NCS S 4502-Y</td> <td width="8%">NCS S 4502-R</td> </tr> <tr> <td width="8%" height="50" bgcolor=""></td> <td width="8%" height="50" bgcolor=""></td> <td width="8%" height="50" bgcolor="#4E5140"></td> <td width="8%" height="50" bgcolor="#515149"></td> </tr> <tr> <td width="8%"></td> <td width="8%"></td> <td width="8%">NCS S 5502-Y</td> <td width="8%">NCS S 5502-R</td> </tr> <tr> <td width="8%" height="50" bgcolor=""></td> <td width="8%" height="50" bgcolor=""></td> <td width="8%" height="50" bgcolor="#363928"></td> <td width="8%" height="50" bgcolor="#363428"></td> </tr> <tr> <td width="8%"></td> <td width="8%"></td> <td width="8%">NCS S 6502-Y</td> <td width="8%">NCS S 6502-R</td> </tr> <tr> <td width="8%" height="50" bgcolor=""></td> <td width="8%" height="50" bgcolor=""></td> <td width="8%" height="50" bgcolor="#171A07"></td> <td width="8%" height="50" bgcolor="#1A180C"></td> </tr> <tr> <td width="8%"></td> <td width="8%"></td> <td width="8%">NCS S 7502-Y</td> <td width="8%">NCS S 7502-R</td> </tr>""" def writetga(width,height,color,filename): f = open(filename,"wb") f.write("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c" % (0,0,2,0,0,0,0,0,0,0,0,0,(width & 0x00ff)%0xff,(width & 0xff00)%0xff,(height & 0x00ff)%0xff,(height & 0xff00)%0xff,0x18,0x0)) for i in range(height): for j in range(width): f.write("%c%c%c" % (int(color[:2],16), int(color[2:4],16), int(color[4:],16))) f.close() tmp = tmp.splitlines() for j, i in enumerate(tmp): if len(i) == 62 and i[48] == "#": writetga(512,512, i[49:55],tmp[j+6][27:-5]+".tga")
Офлайн
Ухтыш-ка!
Работает.
Благодарю!!!
Я думал будет всё сложнее.
Думал, надо будет создавать окно с полотном, на нём рисовать заливку, потом это как-то сохранять картинкой. А тут простой вариант.
Здорово!
Офлайн