Reputation: 1659
I have this html
<tr class="BgWhite">
<td headers="th6" valign="top">
0070648261<br/>QTY: 3
</td>
</tr>
I want to obtain "0070648261" and "3" separately as in ID = 0070648261 and quantity = 3. I was able to use the code below
container1.find("td", {"headers": "th6"}).text.strip()
to produce this output
0070648261<br/>QTY: 3
but how do I split and the output to get
ID = 0070648261 quantity = 3 ?
Upvotes: 2
Views: 54
Reputation: 39
Why not to do that with regex?
import re
s = '<tr class="BgWhite"> <td headers="th6" valign="top">0070648261<br/>QTY: 3</td></tr>'
res = re.findall(r'(\d+)<br/>QTY: (\d+)', s)[0]
print('ID = {} quantity = {}'.format(res[0], res[1]))
Upvotes: 1
Reputation: 6748
Try this.
a="0070648261<br/>QTY: 3"
a=a.split("<br/>")
a="ID = "+a[0]+" quantity ="+a[1].split(':')[1]
Output:
'ID = 0070648261 quantity = 3'
Upvotes: 1