I'm trying to do a little script that writes an html file, this file must have a table which contains two rows that have some information about different products, I managed to get this done, but now I need that this table repeats as many times depending on a previous input data, so for this I thought I could multiply the function which contains the html code but it doesn't work, actually I'm not quite sure what I'm doing here so a little bit of help wouldn't be bad...
This is what I want:
Input ---> How many tables: 3
So the html output file should look something like this
<-- TABLE 1 -->
<table>
<tr>
<td colspan="4" height="30"></td>
</tr>
<tr>
<td width="50" class="width6p"></td>
<td width="260" class="width44p"><img src="http://site/image/CODEPRODUCT_1" width="230" alt="DESCRIPTION_1" style="display:block" border="0" class="width90p"/></td>
<td width="30" class="width3p"></td>
<td width="260" class="width44p"><img src="http://site/image/CODEPRODUCT_2" width="230" alt="DESCRIPTION_2" style="display:block" border="0" class="width90p"/></td>
</tr>
<tr>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_1</span ><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_1</span><br/>
<span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-1</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">PRICE_1</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_2</span><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_2</span><br/>
<span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-2</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">PRICE_2</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
</tr>
<tr>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
</tr>
</table>
<-- TABLE 2 -->
<table>
<tr>
<td colspan="4" height="30"></td>
</tr>
<tr>
<td width="50" class="width6p"></td>
<td width="260" class="width44p"><img src="http://site/image/CODEPRODUCT_1" width="230" alt="DESCRIPTION_1" style="display:block" border="0" class="width90p"/></td>
<td width="30" class="width3p"></td>
<td width="260" class="width44p"><img src="http://site/image/CODEPRODUCT_2" width="230" alt="DESCRIPTION_2" style="display:block" border="0" class="width90p"/></td>
</tr>
<tr>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_1</span ><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_1</span><br/>
<span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-1</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">PRICE_1</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_2</span><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_2</span><br/>
<span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-2</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">PRICE_2</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
</tr>
<tr>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
</tr>
</table>
<-- TABLE 3 -->
<table>
<tr>
<td colspan="4" height="30"></td>
</tr>
<tr>
<td width="50" class="width6p"></td>
<td width="260" class="width44p"><img src="http://site/image/CODEPRODUCT_1" width="230" alt="DESCRIPTION_1" style="display:block" border="0" class="width90p"/></td>
<td width="30" class="width3p"></td>
<td width="260" class="width44p"><img src="http://site/image/CODEPRODUCT_2" width="230" alt="DESCRIPTION_2" style="display:block" border="0" class="width90p"/></td>
</tr>
<tr>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_1</span ><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_1</span><br/>
<span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-1</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">PRICE_1</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_2</span><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_2</span><br/>
<span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-2</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">PRICE_2</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
</tr>
<tr>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
</tr>
</table>
Here is my Python code
import locale
import requests
import urlparse
import json
def html(sku_01,desc_01,sku_precio_1,sku_02,desc_02,sku_precio_2,bloque_prod):
f = open('mkt-output.html','w')
f.write(bloque_prod)
f.close()
if __name__ == '__main__':
sku_01 = raw_input('Ingrese SKU: ')
desc_01 = raw_input('Descripcion de SKU: ')
sku_precio_1 = raw_input('Precio de SKU: ')
sku_02 = raw_input('Ingrese SKU: ')
desc_02 = raw_input('Descripcion de SKU: ')
sku_precio_2 = raw_input('Precio de SKU: ')
bloque_prod = """<table>
<tr>
<td colspan="4" height="30"></td>
</tr>
<tr>
<td width="50" class="width6p"></td>
<td width="260" class="width44p"><img src="http://site/images/{}" width="230" alt="{}" style="display:block" border="0" class="width90p"/></td>
<td width="30" class="width3p"></td>
<td width="260" class="width44p"><img src="http://site/images/{}" width="230" alt="{}" style="display:block" border="0" class="width90p"/></td>
</tr>
<tr>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">{}</span ><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14">{} {}</span><br/>
<span style="font-size:12px;" class="font12">SKU: {}-{}</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">{}</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">{}</span><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14">{} {}</span><br/>
<span style="font-size:12px;" class="font12">SKU: {}-{}</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">{}</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
</tr>
<tr>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/templates/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/templates/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
</tr>
</table>""".format(sku_01,
sku_01,
desc_01,
sku_02,
sku_02,
desc_02,
' '.join(desc_01.split()[0:3]),
' '.join(desc_01.split()[3:-1]),
desc_01.split()[-1],
sku_01[0:-1],
sku_01[-1],
sku_precio_1,
' '.join(desc_02.split()[0:3]),
' '.join(desc_02.split()[3:-1]),
desc_02.split()[-1],
sku_02[0:-1],
sku_02[-1],
sku_precio_2,
sku_01,
sku_02)
html(sku_01, desc_01, sku_precio_1, sku_02, desc_02, sku_precio_2, bloque_prod)
If you need duplicate data written to the HTML file, you could simply have the html() function write variable bloque_prod multiple times by multiplying it:
def html(sku_01,desc_01,sku_precio_1,sku_02,desc_02,sku_precio_2,bloque_prod,tables):
f = open('mkt-output.html','w')
f.write(bloque_prod * tables)
f.close()
Note the addition of the variable tables for the number of table duplicates.
Then, define variable tables in __main()__:
tables = input('Tables: ')
…and add tables into the last line where you call html()
html(sku_01, desc_01, sku_precio_1, sku_02, desc_02, sku_precio_2, bloque_prod,tables)
Are you looking to write different tables?
Also, if it's necessary to annotate which table is currently being printed, you could add an if statement in:
def html(sku_01,desc_01,sku_precio_1,sku_02,desc_02,sku_precio_2,bloque_prod,tables):
f = open('mkt-output.html','w')
rawHTML = ""
for table in range(0, tables):
rawHTML += ("\n<-- TABLE " + str(table) + " -->\n" + bloque_prod)
f.write(rawHTML)
f.close()
(if you wanted the numbering to start at 1, you'd just change str(table) to str(table + 1))
--EDIT-- It seems that you are looking to create tables with different values. I would rewrite the program as such to do this:
import locale
import requests
import urlparse
import json
def createTable(sku_01,desc_01,sku_precio_1,sku_02,desc_02,sku_precio_2):
bloque_prod = """<table>
<tr>
<td colspan="4" height="30"></td>
</tr>
<tr>
<td width="50" class="width6p"></td>
<td width="260" class="width44p"><img src="http://site/images/{}" width="230" alt="{}" style="display:block" border="0" class="width90p"/></td>
<td width="30" class="width3p"></td>
<td width="260" class="width44p"><img src="http://site/images/{}" width="230" alt="{}" style="display:block" border="0" class="width90p"/></td>
</tr>
<tr>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">{}</span ><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14">{} {}</span><br/>
<span style="font-size:12px;" class="font12">SKU: {}-{}</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">{}</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">{}</span><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14">{} {}</span><br/>
<span style="font-size:12px;" class="font12">SKU: {}-{}</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">{}</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
</tr>
<tr>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/templates/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/templates/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
</tr>
</table>""".format(sku_01,
sku_01,
desc_01,
sku_02,
sku_02,
desc_02,
' '.join(desc_01.split()[0:3]),
' '.join(desc_01.split()[3:-1]),
desc_01.split()[-1],
sku_01[0:-1],
sku_01[-1],
sku_precio_1,
' '.join(desc_02.split()[0:3]),
' '.join(desc_02.split()[3:-1]),
desc_02.split()[-1],
sku_02[0:-1],
sku_02[-1],
sku_precio_2,
sku_01,
sku_02)
return bloque_prod
if __name__ == "__main__":
f = open('mkt-output.html','w+') # Open file in w+ mode so we can append to the end
for table in range(0,input("Tables: ")):
print ("--Table "+str(table)+"--")
sku_01 = raw_input('Ingrese SKU: ')
desc_01 = raw_input('Descripcion de SKU: ')
sku_precio_1 = raw_input('Precio de SKU: ')
sku_02 = raw_input('Ingrese SKU: ')
desc_02 = raw_input('Descripcion de SKU: ')
sku_precio_2 = raw_input('Precio de SKU: ')
f.write(createTable(sku_01,desc_01,sku_precio_1,sku_02,desc_02,sku_precio_2))
f.close()
Hope that helps.
Related
i am trying to generate pdf using xhtml2pdf in django for other than english but it shows black square boxes and unusual texts.
i am trying to render nepali text in my pdf but i m getting this issue, can anyone help me to solve this issue ,,
import imp
from io import StringIO
# from weasyprint import HTML
from django.template.loader import render_to_string
import tempfile
from django.http import HttpResponse
from django.conf import settings
import datetime
# A stream implementation using an in-memory bytes buffer
# It inherits BufferIOBase
from django.http import HttpResponse
from django.template.loader import get_template
from xhtml2pdf import pisa # a html2pdf converter
def render_to_pdf(template_src, context_dict={}):
"""
This method will converts the template file into pdf
#params template_src is the template file to be converted
#params context_dict is the dictionary containing all the data written into the template
"""
template = get_template(template_src)
context_dict.update(
{
"invoice_title": context_dict["invoice_title"]
+ str(datetime.datetime.now())
+ ".pdf"
}
)
# this will render the html template and parse the data into the template
html = template.render(context_dict)
# result = StringIO()
response = HttpResponse(content_type="application/pdf")
response["Content-Disposition"] = (
"inline;attachment; filename="
+ context_dict["invoice_title"]
+ str(datetime.datetime.now())
+ ".pdf"
)
response["Content-Transfer-Encoding"] = "utf8"
# part will create the pdf.
# pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result)
pisa_status = pisa.pisaDocument(html.encode("UTF-8"), response)
# pisa_status= pisa.CreatePDF(
# html, dest=response
# )
if pisa_status.err:
return HttpResponse("We had some errors <pre>" + html + "</pre>")
return response
html template:
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Purchase Invoice</title>
<style>
.heading {
font-size: 12px;
font-display: bold;
text-align: center;
padding-top: 50px;
}
.subheading {
font-size: 12px;
text-align: center;
}
.col-12 {
width: 100%;
float: left;
}
.col-3 {
width: 25%;
float: left;
}
.col-6 {
width: 50%;
float: left;
}
.textalignright {
text-align: right;
font-size: 12px;
}
.detail {
font-size: 12px;
/* font-weight: bold; */
}
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
padding: 3px 3px 0px 3px;
}
.w-5 {
width: 10%;
}
.w-25 {
width: 50%;
}
</style>
</head>
<body>
<div class="container">
<div class="Company_profile">
<div class="row">
<div class="col-12 heading">
<h1 class="text-white">{{request.user.company.print_name}}</h1>
</div>
</div>
<div class="row">
<table style="width:100%; border:none;">
<tr style="border:none;">
<td style="width:33.33%; border:none;"></td>
<td style="width:33.33%; border:none; text-align:center;">Email : {{request.user.company.email}}
</td>
<td style="width:33.33%; border:none; text-align:right;">Times Printed :1</td>
</tr>
<tr style="border:none;">
<td style="width:33.33%; border:none;"></td>
<td style="width:33.33%; border:none; text-align:center;">VAT Registration No: {{request.user.company.it_pan}}</td>
<td style="width:33.33%; border:none; text-align:right;">Copy of Original</td>
</tr>
</table>
</div>
<div class="row">
<div class="col-12 subheading">
<h3 class="float-left">कर बिजक</h3>
</div>
</div>
</div>
<div class="Customer_info">
<div class="row">
<table style="width:100%; border:none;">
<tr style="border:none;">
<td style="width:50%; border:none;" class="detail">Invoice No.:{{purchase_data.voucherno}}</td>
<td style="width:50%; border:none; text-align:right;" class="detail">Invoice Date :{{purchase_data.formatted_nepalidate}}</td>
</tr>
<tr style="border:none;">
<td style="width:50%; border:none;" class="detail">Customer Name:{{purchase_data.party.name}}</td>
<td style="width:50%; border:none;"></td>
</tr>
<tr style="border:none;">
<td style="width:50%; border:none;" class="detail">Customer Address :{{purchase_data.party.address}}</td>
<td style="width:50%; border:none;"></td>
</tr>
<tr style="border:none;">
<td style="width:50%; border:none;" class="detail">Customer's VAT/PAN No:{{purchase_data.party.it_pan}}</td>
<td style="width:50%; border:none;"></td>
</tr>
</table>
</div>
</div>
<br />
<br />
<div class="Sales_detail">
<table style="width:100%;">
<thead>
<tr>
<th class="w-5">S.N</th>
<th class="w-25">Particulars</th>
<th class="w-5">Qty</th>
<th class="w-5">Unit </th>
<th class="w-5"> Price</th>
<th class="w-5">Amount</th>
</tr>
</thead>
<tbody>
{% for purchaseItem in purchase_items %}
<tr>
<td scope="row">{{ forloop.counter }}</th>
<td>{{purchaseItem.item.name}}</td>
<td>{{purchaseItem.quantity}}</td>
<td>{{purchaseItem.unit.name}}</td>
<td>{{purchaseItem.formatted_price}}</td>
<td>{% if purchase_data.is_line_discount %}{{purchaseItem.formatted_amount}}{% else %}{{purchaseItem.formatted_amount}}{% endif %}</td>
</tr>
{% endfor %}
<tr>
<td colspan="5" style="text-align:left;">Total Amount</td>
<td>{{purchase_data.total_amount}}</td>
</tr>
<tr>
<td colspan="5" style="text-align:left;">Discount Amount</td>
<td>{{purchase_data.trade_discount_amount}}</td>
</tr>
<tr>
<td colspan="5" style="text-align:left;">Total Taxable Amount</td>
<td>{{purchase_data.taxable_amount}}</td>
</tr>
<tr>
<td colspan="5" style="text-align:left;">13% VAT</td>
<td>{{purchase_data.vat_amount}}</td>
</tr>
<tr>
<td colspan="5" style="text-align:left; font-weight:Bold;">Total NPR Incl. VAT</td>
<td style="font-weight:Bold;">{{purchase_data.total_amount_inc_vat}}</td>
</tr>
</tbody>
</table>
<div class="row">
<div class="col-12 detail">
<p><b>Total Amount in Words :</b> {{purchase_data.formatted_amountwords}}
</p>
</div>
</div>
</div>
<div class="footer" style="margin-top:100px ;">
<table style="width:100%; border:none;">
<tr style="border:none;">
<td style="width:100%; border:none;">
<p class="text-left">(E. & O. E) Goods once sold are not exchangeable or returnable.</p>
</td>
</tr>
<tr style="border:none;">
<td style="width:50%; border:none;"></td>
<td style="width:50%; border:none; text-align:right;">-----------------------------</td>
</tr>
<tr style="border:none;">
<td style="width:50%; border:none;"></td>
<td style="width:50%; border:none; text-align:right;">Authorised Signatory</td>
</tr>
<tr style="border:none;">
<td style="width:50%; border:none;"></td>
<td style="width:50%; border:none; text-align:right;">Printed On : {{purchase_data.formatted_nepalidate}}</td>
</tr>
<tr style="border:none;">
<td style="width:50%; border:none;"></td>
<td style="width:50%; border:none; text-align:right;">Printed By: {{request.user.username}}</td>
</tr>
</table>
</div>
</div>
</body>
</html>
I am getting this output with black square but not the text:
I'm trying to scrape this website using Selenium: https://results.decisiondeskhq.com/2020/primary/colorado/president (if you wanna inspect element, you have to make a quick account to login and see the table I'm trying to scrape). There doesn't appear to be any consistent attributes to the different elements (Candidate, Votes, Pct). How would I go about scraping it?
HTML of the table:
<table class="v-datatable v-table theme--light"><thead><tr><th style="padding-right: 5px; text-align: center;">
</th><th style="padding-right: 5px; text-align: left;">
CANDIDATE
</th><th style="padding-right: 5px; text-align: right;">
VOTES
</th><th style="padding-right: 5px; text-align: right;">
PCT%
</th><th style="padding-right: 5px; text-align: right;">
</th></tr><tr class="v-datatable__progress"><th colspan="5" class="column"></th></tr></thead><tbody><tr><td style="text-align: center;"><i aria-hidden="true" class="v-icon material-icons theme--light" style="color: rgb(37, 116, 169); font-size: 1.2em;">brightness_1</i></td> <td class="winner">Bernie
Sanders
<!----></td> <td class="winner" style="text-align: right;">
355,293
</td> <td class="winner" style="text-align: right;">
37.00%
</td> <td style="padding: 0px 3px;"><i aria-hidden="true" class="v-icon material-icons theme--light" style="color: rgb(87, 174, 166); font-size: 1.2em; font-weight: 700;">check</i></td></tr><tr><td style="text-align: center;"><i aria-hidden="true" class="v-icon material-icons theme--light" style="color: rgb(0, 136, 255); font-size: 1.2em;">brightness_1</i></td> <td class="">Joe
Biden
<!----></td> <td class="" style="text-align: right;">
236,565
</td> <td class="" style="text-align: right;">
24.64%
</td> <td style="padding: 0px 3px;"><!----></td></tr><tr><td style="text-align: center;"><i aria-hidden="true" class="v-icon material-icons theme--light" style="color: rgb(98, 202, 255); font-size: 1.2em;">brightness_1</i></td> <td class="">Michael
Bloomberg
<!----></td> <td class="" style="text-align: right;">
177,727
</td> <td class="" style="text-align: right;">
18.51%
</td> <td style="padding: 0px 3px;"><!----></td></tr><tr><td style="text-align: center;"><i aria-hidden="true" class="v-icon material-icons theme--light" style="color: rgb(197, 239, 247); font-size: 1.2em;">brightness_1</i></td> <td class="">Elizabeth
Warren
<!----></td> <td class="" style="text-align: right;">
168,695
</td> <td class="" style="text-align: right;">
17.57%
</td> <td style="padding: 0px 3px;"><!----></td></tr><tr><td style="text-align: center;"><i aria-hidden="true" class="v-icon material-icons theme--light" style="color: rgb(62, 0, 119); font-size: 1.2em;">brightness_1</i></td> <td class="">Tulsi
Gabbard
<!----></td> <td class="" style="text-align: right;">
10,037
</td> <td class="" style="text-align: right;">
1.05%
</td> <td style="padding: 0px 3px;"><!----></td></tr><tr><td style="text-align: center;"><i aria-hidden="true" class="v-icon material-icons theme--light" style="color: rgb(25, 181, 254); font-size: 1.2em;">brightness_1</i></td> <td class="">Andrew
Yang
<!----></td> <td class="" style="text-align: right;">
3,988
</td> <td class="" style="text-align: right;">
0.42%
</td> <td style="padding: 0px 3px;"><!----></td></tr><tr><td style="text-align: center;"><i aria-hidden="true" class="v-icon material-icons theme--light" style="color: rgb(3, 201, 169); font-size: 1.2em;">brightness_1</i></td> <td class="">Tom
Steyer
<!----></td> <td class="" style="text-align: right;">
3,323
</td> <td class="" style="text-align: right;">
0.35%
</td> <td style="padding: 0px 3px;"><!----></td></tr><tr><td style="text-align: center;"><i aria-hidden="true" class="v-icon material-icons theme--light" style="color: rgb(52, 73, 94); font-size: 1.2em;">brightness_1</i></td> <td class="">Cory
Booker
<!----></td> <td class="" style="text-align: right;">
1,276
</td> <td class="" style="text-align: right;">
0.13%
</td> <td style="padding: 0px 3px;"><!----></td></tr><tr><td style="text-align: center;"><i aria-hidden="true" class="v-icon material-icons theme--light" style="color: rgb(171, 183, 183); font-size: 1.2em;">brightness_1</i></td> <td class="">Roque
De La Fuente III
<!----></td> <td class="" style="text-align: right;">
1,136
</td> <td class="" style="text-align: right;">
0.12%
</td> <td style="padding: 0px 3px;"><!----></td></tr><tr><td style="text-align: center;"><i aria-hidden="true" class="v-icon material-icons theme--light" style="color: rgb(179, 157, 219); font-size: 1.2em;">brightness_1</i></td> <td class="">Marianne
Williamson
<!----></td> <td class="" style="text-align: right;">
1,086
</td> <td class="" style="text-align: right;">
0.11%
</td> <td style="padding: 0px 3px;"><!----></td></tr><tr><td style="text-align: center;"><i aria-hidden="true" class="v-icon material-icons theme--light" style="color: rgb(102, 51, 153); font-size: 1.2em;">brightness_1</i></td> <td class="">Rita
Krichevsky
<!----></td> <td class="" style="text-align: right;">
445
</td> <td class="" style="text-align: right;">
0.05%
</td> <td style="padding: 0px 3px;"><!----></td></tr><tr><td style="text-align: center;"><i aria-hidden="true" class="v-icon material-icons theme--light" style="color: rgb(225, 190, 231); font-size: 1.2em;">brightness_1</i></td> <td class="">Robby
Wells
<!----></td> <td class="" style="text-align: right;">
330
</td> <td class="" style="text-align: right;">
0.03%
</td> <td style="padding: 0px 3px;"><!----></td></tr><tr><td style="text-align: center;"><i aria-hidden="true" class="v-icon material-icons theme--light" style="color: rgb(200, 155, 255); font-size: 1.2em;">brightness_1</i></td> <td class="">Deval
Patrick
<!----></td> <td class="" style="text-align: right;">
227
</td> <td class="" style="text-align: right;">
0.02%
</td> <td style="padding: 0px 3px;"><!----></td></tr><tr><td style="text-align: center;"><i aria-hidden="true" class="v-icon material-icons theme--light" style="color: rgb(102, 203, 178); font-size: 1.2em;">brightness_1</i></td> <td class="">Pete
Buttigieg
<!----></td> <td class="" style="text-align: right;">
0
</td> <td class="" style="text-align: right;">
0%
</td> <td style="padding: 0px 3px;"><!----></td></tr><tr><td style="text-align: center;"><i aria-hidden="true" class="v-icon material-icons theme--light" style="color: rgb(160, 242, 184); font-size: 1.2em;">brightness_1</i></td> <td class="">John K
Delaney
<!----></td> <td class="" style="text-align: right;">
0
</td> <td class="" style="text-align: right;">
0%
</td> <td style="padding: 0px 3px;"><!----></td></tr><tr><td style="text-align: center;"><i aria-hidden="true" class="v-icon material-icons theme--light" style="color: rgb(78, 38, 178); font-size: 1.2em;">brightness_1</i></td> <td class="">Amy
Klobuchar
<!----></td> <td class="" style="text-align: right;">
0
</td> <td class="" style="text-align: right;">
0%
</td> <td style="padding: 0px 3px;"><!----></td></tr></tbody><tfoot><tr><td colspan="100%"><div class="candidate-toggle">Show Less Candidates</div></td></tr></tfoot></table>
My code so far:
from login_info import *
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver = webdriver.Chrome(executable_path="/users/aliallam/Desktop/scraper test/chromedriver")
url = 'https://results.decisiondeskhq.com/2020/primary/colorado/president'
driver.get(url)
# Bypass loading page and click login link
delay = 10 # seconds
login_button = WebDriverWait(driver, delay).until(
EC.presence_of_element_located((By.ID, 'login-text-btn')))
driver.execute_script("arguments[0].click();", login_button)
##
# Login
email = driver.find_element_by_xpath('//*[#id="content"]/div/div/div/form/div[2]/div/div[1]/div/input')
email.send_keys(login_email)
password = driver.find_element_by_xpath('//*[#id="content"]/div/div/div/form/div[3]/div/div[1]/div/input')
password.send_keys(login_pass)
login_button_actual = driver.find_element_by_xpath('//*[#id="content"]/div/div/div/form/button/div')
login_button_actual.click()
##
Thanks in advance!!
You can use below xpath to handle elements from the table. Based on your requirement you can use xpath and handle data.
Retrieve all tr and td
//div[#class='top-line-table']//tbody//tr[*]/td
Retrieve first row
//div[#class='top-line-table']//tbody//tr[1]/td
Retrieve first columns
//div[#class='top-line-table']//tbody//td[1]
Handle thead
//div[#class='top-line-table']//thead/tr[1]/th
I was scraping this website (https://www.ivolatility.com/options/RVX/) using python module request. The output from the selection of the first table using beautifulsoap is above. Now, inside of this first table I am trying to get a specific value (19.17) from this soup obtained from python module requests.
I would like to achieve it using Beautifulsoap, I don't know how to specifically select the cell where it is saved.
Do any of you have any suggestions?
Output from requests:
<table border="0" bordercolor="red" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="3"><script language="JavaScript">
function submitCalcForm(event) {
event.preventDefault();
var form = document.getElementById('basicOptionsForm');
var action = form.action;
var regions = ['', 'USA', 'Europe', 'Asia', 'Canada'];
var regionsOptions = form[1];
var selectedRegion = regionsOptions.options[regionsOptions.selectedIndex].value;
var symbol = form[0].value.trim();
var location = (window.location.href.indexOf('.j')>-1)
? (form.action + '?' + form[0].name + '=' + form[0].value + '&' + form[1].name + '=' + selectedRegion)
: ('/options/'+ ((symbol == '') ? '-' : symbol ) +'/'+regions[selectedRegion]);
window.location.href= location;
}
function goToLookup() {
window.location.href= "/options/-/";
}
</script>
<form action="/options.j" id="basicOptionsForm" method="get" onsubmit="submitCalcForm(event);">
<table bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<table bgcolor="#999999" border="0" cellpadding="0" cellspacing="1">
<tr>
<td bgcolor="#567abb">
<table border="0" cellpadding="1" cellspacing="0" class="table-action">
<tr>
<td><span class="s1w" style="color: #fff;"> Symbol: </span></td><td><input class="s2" name="ticker" size="5" type="text" value="RVX"/></td><td><select class="s2" name="R"><option selected="" value="0">
ALL
</option><option value="1">
USA
</option><option value="2">
Europe
</option><option value="4">
Canada
</option></select></td><td><span class="s2"> </span></td><td><button style="background: #0C6EF8; font-weight: bold; border: 1px solid black;" type="submit">GO!</button></td><td><span class="s2"> </span></td><td><button onclick="goToLookup();" style="background: #0C6EF8; font-weight: bold; border: 1px solid black; color: white; white-space: nowrap;" type="button">
Symbol Lookup</button></td><td><span class="s2"> </span></td>
</tr>
</table>
</td>
</tr>
</table>
</td><td><img border="0" height="1" src="/design/images/0.gif" width="5"/></td><td nowrap=""><b><span class="s4">Russell 2000 Volatility Index</span></b></td><td width="100%"> </td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td colspan="3"><img alt="." border="0" height="10" src="/design/images/0.gif" width="1"/></td>
</tr>
<tr valign="top">
<td width="100%"><script type="text/javascript">
<!--
function wr(s) {
document.write(s);
}
var d = new Array(10);
d[20]='N/A';d[25]='-94.06%';d[30]='32.03%';d[35]='34.74';d[56]='N/A';d[61]='N/A';d[66]='10-Apr';d[71]='84.49%';d[97]='N/A';d[102]='03-Oct';d[107]='29-Mar';d[112]='1.43';d[133]='N/A';d[138]='N/A';d[143]='148.97%';d[148]='98.46%';d[174]='N/A';d[179]='-46.88%';d[184]='198.21%';d[189]='0.27';d[210]='N/A';d[215]='N/A';d[220]='25-May';d[225]='110.30%';d[251]='N/A';d[256]='-68.76%';d[261]='75.38%';d[266]='0';d[287]='N/A';d[292]='N/A';d[297]='39.85%';d[302]='120.02%';d[328]='N/A';d[333]='-67.09%';d[338]='69.94%';d[343]='19.17';d[364]='N/A';d[369]='N/A';d[374]='06-Apr';d[379]='06/14/2018';d[405]='N/A';d[410]='-82.49%';d[415]='74.41%';d[441]='N/A';d[446]='N/A';d[451]='164.16%';d[456]='12.93';d[482]='N/A';d[487]='24-May';d[492]='77.70%';d[518]='N/A';d[523]='03-May';d[528]='21-May';d[533]='12/24/2018';d[559]='N/A';d[564]='59.42%';d[569]='84.78%';
wr('<table class="table-data" cellpadding=1 cellspacing=1 border=0 width=100%>');
wr('<tr bgcolor="#cccccc" align=right height=20>');
wr('<td align="center"><font class=s1>Price</font></td>');
wr('<td align="center"><font class=s1>Change (%)</font><img src="/design/images/0.gif" width=4 height=1 border=0/></td>');
wr('<td align="center"><font class=s1>52 wk High</font><img src="/design/images/0.gif" width=4 height=1 border=0/></td>');
wr('<td align="center"><font class=s1>52 wk Low</font><img src="/design/images/0.gif" width=4 height=1 border=0/></td>');
wr('<td align="center"><font class=s1>Stock volume</font>');
wr('<a href="javascript:openHelp(14)" alt="Open Help">');
wr('<img src="/design/images/ico/q_zn.gif" width=8 height=10 border=0 alt="Open Help"/>');
wr('</a><img src="/design/images/0.gif" width=4 height=1 border=0/></td>');
wr('</tr>');
wr('<tr bgcolor="#FFFFFF" align=right height=20>');
wr('<td align="center"><font class=s1>');
wr(d[343]);
wr('</font></td>');
wr('<td align="center"><font class=s1><nobr> ');
wr('<img src="/design/images/ico/up.gif" alt="+" border=0 align="absmiddle" width=7 height=9/> +');
wr(d[189]);
wr(' (+');
wr(d[112]);
wr('%)</nobr></font></td>');
wr('<td align="center"><font class=s1><nobr> ');
wr(d[35]);
wr(' ');
wr(d[533]);
wr('</nobr></font></td><td align="center"><font class=s1><nobr> ');
wr(d[456]);
wr(' ');
wr(d[379]);
wr('</nobr></font></td>');
wr('<td align="center"><font size=-2 class=s1>');
wr(d[266]);
wr('</font></td>');
wr('</tr></table>');
//-->
</script><img border="0" height="10" src="/design/images/0.gif" width="1"/><table border="0" cellpadding="0" cellspacing="0" class="table-data" width="100%">
<tr align="center" bgcolor="
#cccccc
" height="20">
<td align="center" colspan="2"><font class="s2">Current</font></td><td><font class="s2">1 WK AGO</font></td><td><font class="s2">1 MO AGO</font></td><td><font class="s2">52 wk Hi/Date</font></td><td><font class="s2">52 wk Low/Date</font></td>
</tr>
<tr>
<td align="center" bgcolor="
#FFFFFF
" colspan="5" height="20"><font class="s2" color=""> HISTORICAL VOLATILITY <a alt="Open Help" href="javascript:openHelp(4)"><img alt="Open Help" border="0" height="10" src="/design/images/ico/q_zn.gif" width="8"/></a></font></td>
</tr>
<tr align="center" bgcolor="#ffffff">
<td align="right"><font class="s2">10 days</font></td><td><font class="s2">120.02%</font></td><td><font class="s2">84.49%</font></td><td><font class="s2">74.41%</font></td><td><font class="s2">198.21% - 29-Mar</font></td><td><font class="s2">32.03% - 21-May</font></td>
</tr>
<tr align="center" bgcolor="#eeeeee">
<td align="right"><font class="s2">20 days</font></td><td><font class="s2">110.30%</font></td><td><font class="s2">84.78%</font></td><td><font class="s2">69.94%</font></td><td><font class="s2">164.16% - 06-Apr</font></td><td><font class="s2">39.85% - 25-May</font></td>
</tr>
<tr align="center" bgcolor="#ffffff">
<td align="right"><font class="s2">30 days</font></td><td><font class="s2">98.46%</font></td><td><font class="s2">77.70%</font></td><td><font class="s2">75.38%</font></td><td><font class="s2">148.97% - 10-Apr</font></td><td><font class="s2">59.42% - 24-May</font></td>
</tr>
<tr>
<td align="center" bgcolor="
#FFFFFF
" colspan="5" height="20"><font class="s2" color=""> IMPLIED VOLATILITY <img alt="Open Help" border="0" height="10" src="/design/images/ico/q_zn.gif" width="8"/></font></td>
</tr>
<tr align="center" bgcolor="#ffffff">
<td align="right"><font class="s2">IV Index call <img alt="Open Help" border="0" height="10" src="/design/images/ico/q_zn.gif" width="8"/></font></td><td><font class="s2">N/A</font></td><td><font class="s2">N/A</font></td><td><font class="s2">N/A</font></td><td><font class="s2">N/A - N/A</font></td><td><font class="s2">N/A - N/A</font></td>
</tr>
<tr align="center" bgcolor="#eeeeee">
<td align="right"><font class="s2">IV Index put <img alt="Open Help" border="0" height="10" src="/design/images/ico/q_zn.gif" width="8"/></font></td><td><font class="s2">N/A</font></td><td><font class="s2">N/A</font></td><td><font class="s2">N/A</font></td><td><font class="s2">N/A - N/A</font></td><td><font class="s2">N/A - N/A</font></td>
</tr>
<tr align="center" bgcolor="#ffffff">
<td align="right"><font class="s2">IV Index mean <img alt="Open Help" border="0" height="10" src="/design/images/ico/q_zn.gif" width="8"/></font></td><td><font class="s2">N/A</font></td><td><font class="s2">N/A</font></td><td><font class="s2">N/A</font></td><td><font class="s2">N/A - N/A</font></td><td><font class="s2">N/A - N/A</font></td>
</tr>
<tr>
<td align="center" bgcolor="
#FFFFFF
" colspan="5" height="20"><font class="s2" color="">HISTORICAL 30-DAYS CORRELATION AGAINST S&P 500 Index (SPX)<img alt="Open Help" border="0" height="10" src="/design/images/ico/q_zn.gif" width="8"/></font></td>
</tr>
<tr align="center" bgcolor="#ffffff">
<td align="right"><font class="s2">30 days</font></td><td><font class="s2">-82.49%</font></td><td><font class="s2">-67.09%</font></td><td><font class="s2">-68.76%</font></td><td><font class="s2">-46.88% - 03-Oct</font></td><td><font class="s2">-94.06% - 03-May</font></td>
</tr>
</table>
</td>
</tr>
</table>
The page is dynamic so you'd need to render the page first with something like Selenium.
Also, you can use BeautfifulSoup, or even Selenium, to parse the html once you have it. But I noticed that it's located within <table> tags. Whenever I see a <table> tag, I usually opt to go with pandas' .read_html() as it'll do the hard work for you.
.read_html() will return a list of dataframes, then it's just a matter of finding the data you want, or maniupulate the table as needed. The data you want was found in the dataframe in index position 4, (it was also in position 0, but I choose to go with 4 since it was right there, 2nd row, first column). Then just slice that dataframe to get hat specific cell:
from selenium import webdriver
import pandas as pd
driver = webdriver.Chrome('C:/chromedriver_win32/chromedriver.exe')
url = 'https://www.ivolatility.com/options/RVX/'
driver.get(url)
tables = pd.read_html(driver.page_source)
price = tables[4][0][1]
driver.close()
Output:
print (price)
19.17
my code:
page = requests.get("http://www.freejobalert.com/upsc-recruitment/16960/#Engg-Services2019")
c = page.content
soup=BeautifulSoup(c,"html.parser")
tables=soup.find_all("table",{"style":"width: 500px;"})
Html table:
<table style="width: 500px;" border="2">
<tbody>
<tr>
<td colspan="2">
<p style="text-align: center;"><span style="color: #ff0000;"><strong>Union Public Service Commission (UPSC)</strong></span></p>
<p style="text-align: center;"><span style="color: #ff00ff;"><strong>Advt No.01/2019</strong></span></p>
<p style="text-align: center;"><span style="color: #008000;"><strong><strong><strong>Engineering Services (Prelims) Exam 2019</strong></strong></strong></span></p>
<p style="text-align: center;"><strong>WWW.FREEJOBALERT.COM</strong></p>
</td>
</tr>
<tr>
<td style="text-align: center;" colspan="2"><span style="color: #ff0000;"><strong>Application Fee</strong></span></p>
<ul>
<li style="text-align: left;"><span style="line-height: 19px;">For Female/SC/ST/ PH: <strong>NIL</strong></span></li>
<li style="text-align: left;"><span style="line-height: 19px;">For Others: <strong>Rs. 200/-</strong></span></li>
<li style="text-align: left;">Candidates can pay either by depositing the money in any Branch of SBI by cash or by using net banking facility of SBI.</li>
</ul>
</td>
</tr>
<tr>
<td style="text-align: center;" colspan="2"><span style="color: #ff0000;"><strong><strong>Important Dates</strong></strong></span></p>
<ul>
<li style="text-align: left;">Starting Date to Apply Online: <strong>26-09-2018</strong></li>
<li style="text-align: left;"><span style="line-height: 19px;">Last Date to Apply Online: <strong>22-10-2018 till 06:00 PM</strong></span></li>
<li style="text-align: left;"><span style="line-height: 19px;">Date for Preliminary Exam:<strong> 06-01-2019</strong></span></li>
<li style="text-align: left;"><span style="line-height: 19px;">Last date for Fee Payment (Pay by cash):<strong> 21-10-2018 at 11.59 PM</strong></span></li>
<li style="text-align: left;"><span style="line-height: 19px;">Last date for Fee Payment (online):<strong> 22-10-201</strong></span><strong>8 till 06:00 PM</strong></li>
</ul>
</td>
</tr>
</tbody>
</table>
I am expecting:
[
<td colspan="2">
<p style="text-align: center;"><span style="color: #ff0000;"><strong>Union Public Service Commission (UPSC)</strong></span></p>
<p style="text-align: center;"><span style="color: #ff00ff;"><strong>Advt No.01/2019</strong></span></p>
<p style="text-align: center;"><span style="color: #008000;"><strong><strong><strong>Engineering Services (Prelims) Exam 2019</strong></strong></strong></span></p>
<p style="text-align: center;"><strong>WWW.FREEJOBALERT.COM</strong></p>
</td>
]
how can i get these part of html using beautiful soup without using loop..
i want all with colspan="2"
please have a look into this code..
Thanks....
What prevent you to directly find_all that element?
from bs4 import BeautifulSoup
import requests
page = requests.get("http://www.freejobalert.com/upsc-recruitment/"
"16960/#Engg-Services2019")
c = page.content
soup = BeautifulSoup(c,"html.parser")
tables = soup.find_all("td", attrs={'colspan':'2'})
print(tables)
Code I'm using for PDF generation:
html = HTML(string=final_html, base_url=request.build_absolute_uri())
main_doc = html.render()
pdf = main_doc.write_pdf()
This is the content of final_html string:
<body style="width:100%; height:100%;">
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
font-family: 'Open Sans', sans-serif;
font-size: 14px;
}
table {
margin-top: 0px;
}
th, td {
padding: 5px;
}
.bottom {
vertical-align: bottom;
}
tr.noBorder td {
border: 0;
}
</style> <table style="width:100%; height:100%;">
<tr>
<td COLSPAN="2" style="border-right-style: hidden;">
<div style="float: left; display:inline;">
<div>
<div><strong>-seller_name-</strong></div>
</div>
</div>
</td>
<td COLSPAN=2>
<div style="float: right; display:inline;">
<div style="text-align: center">
<strong>-label_name-</strong>
</div>
<div>
-crnbarcodeimage-
</div>
<div style="text-align: center">
<strong>*-label_number-*</strong>
</div>
</div>
</td>
</tr>
<tr>
<td COLSPAN=2>Name & Delivery Address</td>
<td style="border-right-style: hidden;">Payment Mode</td>
<td style="float: right; border-left-style: hidden; border-top-style: hidden; border-bottom-style: hidden;">
<strong>-order_type-</strong></td>
</tr>
<tr>
<td COLSPAN=2>
<div><strong>-drop_name-</strong></div>
<br>
<div>-drop_address-</div>
<br>
<div>-drop_state- <strong>-drop_pincode-</strong></div>
<br>
<div><strong>Contact Number: -drop_phone-</strong></div>
</td>
<td valign="top" COLSPAN=2>
<div style="float: left;">
<strong>Order No.:</strong>
</div>
<div style="float: right;">
-seller_order_id-
</div>
<div>
<div>
-seller_order_id_barcode-
</div>
</div>
<div style="float: left;">
<strong>Invoice No.</strong>
</div>
<div style="float: right;">
-invoice_number-
</div>
</td>
</tr>
<tr>
<td COLSPAN=4 ALIGN=RIGHT>
</td>
</tr>
<tr>
<td>Description</td>
<td>QTY</td>
<td>Rate</td>
<td>Amount</td>
</tr>
<tr>
<td>-item-</td>
<td>1</td>
<td>-invoice_value-</td>
<td>-invoice_value-</td>
</tr>
<tr>
<td COLSPAN=3 ALIGN=LEFT style="border-right-style:hidden;">Total</td>
<td COLSPAN=1 ALIGN=LEFT style="border-left-style:hidden;">-invoice_value-</td>
</tr>
<tr>
<td COLSPAN=3 ALIGN=LEFT style="border-right-style:hidden;"><strong>COD Amount</strong></td>
<td COLSPAN=1 ALIGN=LEFT style="border-left-style:hidden;"><strong>-cod_value-</strong></td>
</tr>
<tr>
<td COLSPAN=4>
Prices are inclusive of all applicable taxes
</td>
</tr>
<tr>
<td COLSPAN=4 style="border-bottom-style:hidden;">If Undelivered, please return to:</td>
</tr>
<tr>
<td COLSPAN=4>
<strong>
<div>B-220/2, 1st Floor, Right Door, Savitri Nagar, New Delhi: 110017 Ph. 8376035546</div>
</strong>
</td>
</tr> </table> </body> </html>
The pdf is always generated as partial of the page while I want it to cover entire pdf page.
I think that you might have to add this to your styles to configure the page:
#page {
size: 11cm 14.1cm;
margin-left: 0.5cm;
margin-top: 0.5cm;
}