Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Something like this.</p> <pre><code>import re from BeautifulSoup import BeautifulSoup html = '&lt;h2 name="PRM-013113-21017-0FSNS" class="pointer"&gt;&lt;a name="PRM-013113-21017-0FSNS"&gt;Chinese New Year Sale&lt;br&gt;&lt;span&gt;February 8, 2013 - February 10, 2013&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;' date_span = BeautifulSoup(html).findAll('h2', {'class' : 'pointer'})[0].findAll('span')[0] date = re.findall(r'&lt;span&gt;(.+?)&lt;/span&gt;', str(date_span))[0] </code></pre> <p><em>(PS: you can also use BeautifulSoup's <code>text=True</code> method with <code>findAll</code> to get the text instead of using regex as follows.)</em></p> <pre><code>from BeautifulSoup import BeautifulSoup html = '&lt;h2 name="PRM-013113-21017-0FSNS" class="pointer"&gt;&lt;a name="PRM-013113-21017-0FSNS"&gt;Chinese New Year Sale&lt;br&gt;&lt;span&gt;February 8, 2013 - February 10, 2013&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;' date = BeautifulSoup(test).findAll('h2', {'class' : 'pointer'})[0].findAll('span')[0] date = date.findAll(text=True)[0] </code></pre> <h3>Update::</h3> <p>To have a start and end date as separate variables you can simply split them you can simply split the date variable as follows:</p> <pre><code>from BeautifulSoup import BeautifulSoup html = '&lt;h2 name="PRM-013113-21017-0FSNS" class="pointer"&gt;&lt;a name="PRM-013113-21017-0FSNS"&gt;Chinese New Year Sale&lt;br&gt;&lt;span&gt;February 8, 2013 - February 10, 2013&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;' date = BeautifulSoup(test).findAll('h2', {'class' : 'pointer'})[0].findAll('span')[0] date = date.findAll(text=True)[0] # Get start and end date separately date_start, date_end = date.split(' - ') </code></pre> <p>now <code>date_start</code> variable contains the starting date and <code>date_end</code> variable contains the ending date.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload