How to use Python with beautifulsoup to merge siblings
<p>How do I merge siblings together and display the output one beside each other. </p>

<p><strong>EX.</strong></p>

<pre><code>dat="""
&lt;div class="col-md-1"&gt;
&lt;table class="table table-hover"&gt;
&lt;tr&gt;
&lt;th&gt;Name:&lt;/th&gt;
&lt;td&gt;&lt;strong&gt;John&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;Last Name:&lt;/th&gt;
&lt;td&gt;Doe&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;Email:&lt;/th&gt;
&lt;td&gt;jd@mail.com&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
"""

soup = BeautifulSoup(dat, 'html.parser')
for buf in soup.find_all(class_="table"):
   ope = buf.get_text("\n", strip=True)
   print ope
</code></pre>

<p><strong>When run it produces:</strong></p>

<pre><code>Name:
John
Last Name:
Doe
Email:
jd@mail.com
</code></pre>

<p><strong>What I need:</strong></p>

<pre><code>Name: John
Last Name: Doe
Email: jd@mail.com
</code></pre>

<p>Can it be done in a list and every new "tr" tag put a new line?</p>

<p><strong>EDIT:</strong>
 <a href="http://stackoverflow.com/users/771848/alecxe">alecxe</a> answer worked but strangely after the output I would get "ValueError: need more than 1 value to unpack" To fix that just put a try:except block.</p>

<pre><code>soup = BeautifulSoup(dat, 'html.parser')
for row in soup.select(".table tr"):
 try:   
         (label, value) = row.find_all(["th", "td"])
     print(label.get_text() + " " + value.get_text())
 except ValueError:
     continue
</code></pre>

<p>Why don't process the table <em>row by row</em>:</p>

<pre><code>soup = BeautifulSoup(dat, 'html.parser')
for row in soup.select(".table tr"):
    label, value = row.find_all(["th", "td"])
    print(label.get_text() + " " + value.get_text())
</code></pre>

<p>Prints:</p>

<pre><code>Name: John
Last Name: Doe
Email: jd@mail.com
</code></pre>

python html