By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

How do I change HTML code to dictionary?

P: 1
How can I change HTML into a dictionary.
So what I mean is I have some html code...
Expand|Select|Wrap|Line Numbers
  1. <center> <div id="header-content">
  2.             <div id="header-content-left">
  3.                 <a href="index.html" target="_top"><img src="header-image.jpg" id="header-image" alt="Pager"></img><a/>
  4.             </div>
  5.             <div id="header-content-right">
  6.                 <a href="create.html" target="_top"><button id="header-content-right-cp">
  7.                     <p style="font-family:Calibri; font-size:20px; text-align:center;"> Create </p>
  8.                 </button></a>
  9.                 <button id="header-content-right-si">
  10.                     <p style="font-family:Calibri; font-size:20px; text-align:center;" onclick="login()"> Login </p>
  11.                 </button>
  12.                 <button id="header-content-right-so">
  13.                     <p style="font-family:Calibri; font-size:20px; text-align:center;" onclick="logout()"> Logout </p>
  14.                 </button>
  15.                 <div id="header-content-right-pr">
  16.                     <a href="account.html" target="_top"><p style="margin-top:7px; font-family:Calibri; font-size:18px; text-align:center;"> kMcMaxPicAxeYT991 </p></a>
  17.                 </div>
  18.             </div>
  19.             <div id="header-content-right-phone">
  20.  
  21.             </div>
  22.         </div> </center>
and I want it to look like a dictionary...
Expand|Select|Wrap|Line Numbers
  1. {"center":
  2.     {
  3.     "div id="header-content"":
  4.         {
  5.         "div id="header-content-left":
  6.             {
  7.             "a href="index.html" target="_top":
  8.                 {
  9.                 "img src="header-image.jpg" id="header-image"": None
  10.                 }
  11.             }
  12.         "div id="header-content-right"":
  13.             {
  14.             "a href="create.html" target="_top"":
  15.                 {
  16.                 "button id="header-content-right-cp"":
  17.                     {
  18.                     "p style="font-family:Calibri; font-size:20px; text-align:center;"": "Create"
  19.                     }
  20.                 }
  21.             "button id="header-content-right-si"":
  22.                 {
  23.                 "p style="font-family:Calibri; font-size:20px; text-align:center;" onclick="login()"": "Login"
  24.                 }
  25.             "button id="header-content-right-so"":
  26.                 {
  27.                 "p style="font-family:Calibri; font-size:20px; text-align:center;" onclick="logout()"": "Logout"
  28.                 } 
  29.             "div id="header-content-right-pr"":
  30.                 {
  31.                 "a href="account.html" target="_top"":
  32.                     {
  33.                     "p style="margin-top:7px; font-family:Calibri; font-size:18px; text-align:center;"": "kMcMaxPicAxeYT991"
  34.                     }
  35.                 }
  36.             }
  37.         "div id="header-content-right-phone"": None
  38.         }
  39.     }
  40. }
  41.  
Of course I can't just do it myself because different html will be entered each time.
Thanks for the help.
Apr 11 '15 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 621
Once you get deeper than a dictionary of dictionaries you should be using SQL IMHO, which can be used to find a match on multiple fields if that is what you want to do. See this link for starters http://zetcode.com/db/sqlitepythontutorial/
Apr 11 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.