how to get partial text from a long tag using BeautifulSoup
<p>I have been studying a shopping website, and I want to extract the brandname and the product name from its html code like the following:</p>

<p><code>&lt;h1 class="product-name elim-suites"&gt;Chantecaille&lt;span itemprop="name" &gt;Limited Edition Protect the Lion Eye Palette&lt;/span&gt;&lt;/h1&gt;</code></p>

<p>I tried: <code>results = soup.findAll("h1", {"class" : "product-name elim-suites"})[0].text</code></p>

<p>and got: <code>u'ChantecailleLimited Edition Protect the Lion Eye Palette'</code></p>

<p>As you can see, Chantecaille is the brandname, the rest is the product name, but they are now sticked to each other, any suggestion? Thank you!</p>

<p>You could use <em>get_text</em> and pass a character to separate the text or pull the text using <code>. h1.find(text=True, recursive=False)</code> on the <code>h1</code> and pull the text from the <em>span</em> directly:</p>

<pre><code>In [1]: h ="""&lt;h1 class="product-name elim-suites"&gt;Chantecaille&lt;span itemprop="name" &gt;Limited Edition Protect the Lion Eye Palette
   ...: &lt;/span&gt;&lt;/h1&gt;"""

In [2]: from bs4 import BeautifulSoup

In [3]: soup = BeautifulSoup(h, "html.parser")

In [4]: h1 = soup.select_one("h1.product-name.elim-suites")

In [5]: print(h1.get_text("\n"))
Chantecaille
Limited Edition Protect the Lion Eye Palette


In [6]: prod, desc = h1.find(text=True, recursive=False), h1.span.text

In [7]: print(prod, desc)
(u'Chantecaille', u'Limited Edition Protect the Lion Eye Palette\n')
</code></pre>

<p>Or if text could appear after the <em>span</em> also use <em>find_all</em>:</p>

<pre><code>In [8]: h ="""&lt;h1 class="product-name elim-suites"&gt;Chantecaille
&lt;span itemprop="name" &gt;Limited Edition Protect the Lion Eye Palette&lt;/span&gt;other text&lt;/h1&gt;"""


In [9]: from bs4 import BeautifulSoup

In [10]: soup = BeautifulSoup(h, "html.parser")

In [11]: h1 = soup.select_one("h1.product-name.elim-suites")

In [12]: print(h1.get_text("\n"))
Chantecaille
Limited Edition Protect the Lion Eye Palette
other text

In [13]: prod, desc = " ".join(h1.find_all(text=True, recursive=False)), h1.span.text

In [14]: 

In [14]: print(prod, desc)
(u'Chantecaille other text', u'Limited Edition Protect the Lion Eye Palette')
</code></pre>

python parsing beautifulsoup