python 3.x - How to use "for" and "while" to capture cell tags from multiple tables in an html file? -


i have several html files need capture data inside tables, launch in database, not able navigate html tree find tags cells, html this:

<div class="details">    <div class="title-table"><h2> beaune</h2>     <div class="table-responsive">   <div class="table-towers">     <div id="table472dc5e9b46304cf95865f7db6c459aa" class="collapse in table-content">        <div class="table-towers">              <div class="table-row">                 <div class="table-cell build_type">apartamento</div>                 <div class="table-cell area_useful">220m²</div>                 <div class="table-cell rooms">3</div>                 <div class="table-cell garage">4</div>                 <div class="table-cell bird_estimate_average">r$ 2.816.344,33*         <p><small>(r$ 2.393.892,68 r$ 3.238.795,98)</small></p>     </div>              <div class="table-row">     <div class="table-cell build_type">cobertura</div>                 <div class="table-cell area_useful">396m²</div>                 <div class="table-cell rooms">3</div>                 <div class="table-cell garage">5</div>                 <div class="table-cell bird_estimate_average">r$ 5.069.419,80*                          <p><small>(r$ 4.309.006,83 r$ 5.829.832,77)</small></p>                  </div> <div class="title-table"><h2>bergerac</h2>   <div class="table-responsive">       <div class="table-towers">            <div id="table0b60c9a0a450b921186c91102da447d9" class="collapse table-content">                <div class="table-towers">                    <div class="table-row">                         <div class="table-cell build_type">apartamento</div>                 <div class="table-cell area_useful">220m²</div>                 <div class="table-cell rooms">3</div>                 <div class="table-cell garage">4</div>                 <div class="table-cell bird_estimate_average">r$ 2.816.344,33*                            <p><small>(r$ 2.393.892,68 r$ 3.238.795,98)</small></p>              </div>                                         <!-- asdasd -->             </div>                     </div> 

i have 10 more tables, inside html file, follows same structure, thought i'd make "for" bring "title-table" tag, name of table this:

for id_towers in soup.find("div",{"class":"details"}).findall("div",{"class":"title-table"}):#.findall("h2"):     nm = id_torre.find("h2")     print(nm) 

and list of table titles, thought of "while" finds table each title , captures data of cells in each line, later launch in database:

while len(id_towers) >0:     nm = id_towers     print(nm)      tp = soup.find("div",{"class":id_torre}).find("div",{"class":"table-cell build_type"})     print(tp)      m2_useful = soup.find("div",{"class":id_torre}).find("div",{"class":"table-cell area_useful"})     print(m2_useful)      roms = soup.find("div",{"class":id_torre}).find("div",{"class":"table-cell rooms"})     print(roms) 

but brings "none" in fields , loops endlessly. what's wrong code? i'm new programming , python first language i'm learning.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -