Getting data from Website back to excel - excel

I'm trying to automate a page scrape program in Excel using VBA but having difficulty getting the results from the webpage as the fields I want do not have id's, I have copied the source code below I think its contained within a table? how do you get the data using td Class and class?
<table>
<tbody>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Date of Liability</span></td>
<td class="vehicledetailstableright"><span class="bodytext">01 07 2014</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Date of First Registration</span></td>
<td class="vehicledetailstableright"><span class="bodytext">02 07 2013</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Year of Manufacture</span></td>
<td class="vehicledetailstableright"><span class="bodytext">2013</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Cylinder Capacity (cc)</span></td>
<td class="vehicledetailstableright"><span class="bodytext">2993cc</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">CO₂ Emissions</span></td>
<td class="vehicledetailstableright"><span class="bodytext">129 g/km</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Fuel Type</span></td>
<td class="vehicledetailstableright"><span id="fueltype" class="bodytext">HEAVY OIL</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Export Marker</span></td>
<td class="vehicledetailstableright"><span id="exportmarker" class="bodytext">N</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Vehicle Status</span></td>
<td class="vehicledetailstableright"><span id="vehiclelicencestatus" class="bodytext">Licence Not Due</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Vehicle Colour</span></td>
<td class="vehicledetailstableright"><span id="colour" class="bodytext">BLUE</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Vehicle Type Approval</span></td>
<td class="vehicledetailstableright"><span class="bodytext">M1</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Date of Last V5C Issued</span>
</td>
<td class="vehicledetailstableright"><span class="bodytext">No Result Found</span>
</td>
</tr>

Tim is suggesting a code heavy way to do it, and it is technically correct. I suggest the same thing repeatedly here:
VBA spliting results from html imported table into excel
Basically, use the macro recorder, and then create a HTML query for data.
see my blog post on this as well.
http://automatic-office.com/?p=344
Many ways to skin the cat, but this is the easy way.

Related

Need the full correct html code for this Table

Image table
Please write full html codes for this table. You may see the Table image from above via the link.
<table border="1" width="800">
<tr>
<th>Level1</th>
<th>Level2</th>
<th>Level2</th>
<th>Info</th>
<th>Name</th>
</tr>
<tr>
<td rowspan="6">System</td>
</tr>
<tr>
<td rowspan="4">System Apps</td>
<td rowspan="2">System Memory</td>
</tr>
<tr>
<td rowspan="3">SystemEnv</td>
<td rowspan="1">SystemEnv2</td>
<td rowspan="2">Memeory Test</td>
</tr>
Here is the table code :
<table border="2">
<tr>
<th>Level 1</th>
<th>Level 2</th>
<th>Level 3</th>
<th>info</th>
<th>Name</th>
</tr>
<tr>
<td rowSpan="6">System</td>
<td rowSpan="4">System apps</td>
<td rowSpan="3">SystemEnv</td>
<td>App Text</td>
<td>foo</td>
</tr>
<tr>
<td>App memory</td>
<td>foo</td>
</tr>
<tr>
<td>App test</td>
<td>bar</td>
</tr>
<tr>
<td>Systemenv2</td>
<td>App test</td>
<td>bar</td>
</tr>
<tr>
<td rowSpan="2">System Memory</td>
<td rowSpan="2">Memory test</td>
<td>memory func</td>
<td>foo</td>
</tr>
<tr>
<td>Memory Func</td>
<td>foo</td>
</tr>
</table>

Use HTML Table without headers

I've a table, where the normal guidance for HTML tables arn't followed.
My best move will be, to just create a proper JSON-object, and using that.
But i'll like to ask, if there is any options for parsing an HTML table, "without headers", and define them in Tabulator, instead.
I know the case id odd, but i'll just like to hear :-)
Example where no thead and th is in the HTML-source:
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr height="16">
<td colspan="16">
Something
</td>
<td colspan="16">
14
</td>
<td colspan="16">
2020-01-28
</td>
</tr>
</tbody>
</table>
Im afraid not.
When Tabulator is built on a table element, it parses the HTML to create a JavaScript object for each row of the table, using the column headers as property names.
Without headers it would have no reasonable way to map the column values onto an object.
I solve problem like this
<table border="0" cellpadding="0" cellspacing="0">
<tr height="16" hidden>
<td colspan="16">
</td>
<td colspan="16">
</td>
<td colspan="16">
</td>
</tr>
<tr height="16">
<td colspan="16">
Something
</td>
<td colspan="16">
14
</td>
<td colspan="16">
2020-01-28
</td>
</tr>
</table>

Convert linked images to embedded images

i have an excel file with many images inside.
Actually, this excel files was made with HTML code that converted to excel file and the images were linked to their respective image. ( The reason i made the file with excel is because there is about 700+ images and i cant make it manually from 1. It will takes so much time to finish)
here is my excel's HTML code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table>
<thead>
<tr>
<th>No</th>
<th>Image</th>
<th>Title</th>
</tr>
</thead>
<tbody>
<tr>
<td >1</td>
<td><img src="56.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >2</td>
<td><img src="57.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >3</td>
<td><img src="58.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >4</td>
<td><img src="59.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >5</td>
<td><img src="60.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >6</td>
<td><img src="61.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >7</td>
<td><img src="62.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >8</td>
<td><img src="63.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >9</td>
<td><img src="64.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >10</td>
<td><img src="65.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >11</td>
<td><img src="66.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >12</td>
<td><img src="67.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >13</td>
<td><img src="68.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >14</td>
<td><img src="69.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >15</td>
<td><img src="70.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >16</td>
<td><img src="71.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >17</td>
<td><img src="72.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >18</td>
<td><img src="73.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >19</td>
<td><img src="74.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >20</td>
<td><img src="75.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >21</td>
<td><img src="76.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >22</td>
<td><img src="77.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >23</td>
<td><img src="78.jpg" width="200px"/></td>
<td></td>
</tr>
<tr>
<td >24</td>
<td><img src="79.jpg" width="200px"/></td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>
The problem is, when i save it and send the excel file to other's PC, the images will be blank. Here's the screenshot
i tried to google the problem but still i couldn't find the solution yet.
Any method to convert all the images to embedded images?
Thank you
I wrote a VBA script to convert all linked images to embedded images.
This script will have errors if there are shapes which aren't images. It also assumes that embedded images have their link in their alt text, which I found to be the case in my situation.
Sub INSERT_PICS()
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
Debug.Print shp.Name
Debug.Print shp.AlternativeText
ActiveSheet.Shapes.AddPicture Filename:=shp.AlternativeText, linktofile:=msoFalse, _
savewithdocument:=msoCTrue, Left:=shp.Left, Top:=shp.Top, Width:=shp.Width, Height:=shp.Height
shp.Delete
Next shp
End Sub

How to pass product TVs to SimpleCart's scGetCart snippet?

I need some TVs (weight, dimensions, etc) I've associated with my products to appear in the Cart page of my SimpleCart site.
Problem is I have no idea how to do this. I don't understand how the SimpleCart cart is built and there isn't documentation for this.
Would anyone know how I can show TVs associated with each product in the cart output chunk?
The cart snippet has the following code which gets data from the cart and puts it into Chunks:
$sc = $modx->getService('simplecart','SimpleCart',$modx->getOption('simplecart.core_path',null,$modx->getOption('core_path').'components/simplecart/').'model/simplecart/',$scriptProperties);
if (!($sc instanceof SimpleCart)) return '';
 
$controller = $sc->loadController('Cart');
$output = $controller->run($scriptProperties);
The output Chunk looks like:
<div id="simplecart">
<form action="[[~[[*id]]]]" method="post" id="form_cartoverview">
<input type="hidden" name="updatecart" value="true" />
<table>
<tr>
<th class="desc">[[%simplecart.cart.description]]</th>
<th class="price">[[%simplecart.cart.price]]</th>
<th class="quantity">[[%simplecart.cart.quantity]]</th>
[[+cart.total.vat_total:notempty=`<th class="quantity">[[%simplecart.cart.vat]]</th>`:isempty=``]]
<th class="subtotal">[[%simplecart.cart.subtotal]]</th>
<th> </th>
</tr>
[[+cart.wrapper]]
[[+cart.total.discount:notempty=`<tr class="total first discount">
<td colspan="[[+cart.total.vat_total:notempty=`3`:isempty=`2`]]"> </td>
<td class="label">[[%simplecart.cart.discount]]</td>
<td class="value">- [[+cart.total.discount_formatted]]</td>
<td class="extra">[[+cart.total.discount_percent:notempty=`([[+cart.total.discount_percent]]%)`:isempty=` `]]</td>
</tr>`:isempty=``]]
[[+cart.total.vat_total:notempty=`
<tr class="total [[+cart.total.discount:notempty=`second`:isempty=`first`]]">
<td colspan="3"> </td>
<td class="label">[[%simplecart.cart.total_ex_vat]]</td>
<td class="value">[[+cart.total.price_ex_vat_formatted]]</td>
<td class="extra"> </td>
</tr>
[[+cart.vat_rates]]
<tr class="total [[+cart.total.discount:notempty=`third`:isempty=`second`]]">
<td colspan="3"> </td>
<td class="label">[[%simplecart.cart.total_vat]]</td>
<td class="value">[[+cart.total.vat_total_formatted]]</td>
<td class="extra"> </td>
</tr>
<tr class="total [[+cart.total.discount:notempty=`fourth`:isempty=`third`]]">
<td colspan="3"> </td>
<td class="label">[[%simplecart.cart.total_in_vat]]</td>
<td class="value">[[+cart.total.price_formatted]]</td>
<td class="extra"> </td>
</tr>
`:isempty=`
<tr class="total [[+cart.total.discount:notempty=`second`:isempty=`first`]]">
<td colspan="2"> </td>
<td class="label">[[%simplecart.cart.total]]</td>
<td class="value">[[+cart.total.price_formatted]]</td>
<td class="extra"> </td>
</tr>
`]]
</table>
<div class="submit">
<input type="submit" value="[[%simplecart.cart.update]]" />
</div>
</form>
This does appear to be documented:
Product Options (TVs)
and to output them:
Modifying the Product Template
It appears that you would just output them normally [[*myProductOptions]]
Though, it appears that your template is using a placeholder, I would try
[[+cart.myProductOptions] as well. If all else fails you might try debugging the simplecart class and dump the array of product data before it populates the chunk, there might be a clue in there.
Found (through trial and error) you must use:
[[+product.tv.name_of_tv]]

Tinymce copy/paste from excel (Plugin BBcode)

I'm using tinyMCE, below you can see the implementation.
Now the problem: when I copy some records from EXCEL and paste them in my tinymce field. It's displayed good enough for me (with plugin: paste, he will actually show the fields)
When i ask the value from my field I get a return with a table struct depeding what you paste. But I don't want any html, see below what I want.
Implementation code:
tinyMCE.init({
mode : "exact",
elements: "id",
theme : "advanced",
plugins : "bbcode, inlinepopups",
content_css : "tinymce.css",
entity_encoding : "raw",
remove_linebreaks : false,
forced_root_block: false,
force_br_newlines: true,
invalid_elements : "p, div, span",
force_p_newlines: false, t
heme_advanced_buttons1 : $cur_buttons,
theme_advanced_buttons2: "",
theme_advanced_buttons3: "",
init_instance_callback : "tiny_mce_callback"});
Return from tinyMCE object:
<table style="border-collapse: collapse;" width="216" border="0"
cellspacing="0" cellpadding="0">
<!--StartFragment-->
<colgroup>
<col style="mso-width-source: userset; mso-width-alt: 1152;" width="27"/>
<col width="55" />
<col style="mso-width-source: userset; mso-width-alt: 2858;"
span="2" width="67"/>
</colgroup>
<tbody>
<tr style="mso-height-source: userset;">
<td class="xl24" width="27" height="12">1</td>
<td class="xl26" width="55">26/05/12</td>
<td class="xl24" width="67">Amsterdam</td>
<td class="xl24" width="67">Casablanca</td>
</tr>
<tr style="mso-height-source: userset;">
<td class="xl24" height="12">2</td>
<td class="xl25">27/05/12</td>
<td class="xl24">Casablanca</td>
<td class="xl24">Rabat</td>
</tr>
<tr style="mso-height-source: userset;">
<td class="xl24" height="12">3</td>
<td class="xl25">28/05/12</td>
<td class="xl24">Rabat</td>
<td class="xl24">Fes</td>
</tr>
<tr style="mso-height-source: userset;">
<td class="xl24" height="12">4</td>
<td class="xl25">29/05/12</td>
<td class="xl24">Fes</td>
<td class="xl24"> </td>
</tr>
<tr style="mso-height-source: userset;">
<td class="xl24" height="12">5</td>
<td class="xl25">30/05/12</td>
<td class="xl24">Fes</td>
<td class="xl24">Erg Chebbi</td>
</tr>
<tr style="mso-height-source: userset;">
<td class="xl24" height="12">6</td>
<td class="xl25">31/05/12</td>
<td class="xl24">Erg Chebbi</td>
<td class="xl24">Dades Vallei</td>
</tr>
<tr style="mso-height-source: userset;">
<td class="xl24" height="12">7</td>
<td class="xl25">01/06/12</td>
<td class="xl24">Dades Vallei</td>
<td class="xl24">Ouarzazate</td>
</tr>
<tr style="mso-height-source: userset;">
<td class="xl24" height="12">8</td>
<td class="xl25">02/06/12</td>
<td class="xl24">Ouarzazate</td>
<td class="xl24">Marrakesh</td>
</tr>
<tr style="mso-height-source: userset;">
<td class="xl24" height="12">9</td>
<td class="xl25">03/06/12</td>
<td class="xl24">Marrakesh</td>
<td class="xl24"> </td>
</tr>
<tr style="mso-height-source: userset;">
<td class="xl24" height="12">10</td>
<td class="xl25">04/06/12</td>
<td class="xl24">Marrakesh</td>
<td class="xl24"> </td>
</tr>
<tr style="mso-height-source: userset;">
<td class="xl24" height="12">11</td>
<td class="xl25">05/06/12</td>
<td class="xl24">Marrakesh</td>
<td class="xl24">Amsterdam</td>
</tr>
<!--EndFragment--></tbody>
</table>
Expected return:
1 26/05/12 Amsterdam Casablanca
2 27/05/12 Casablanca Rabat
3 28/05/12 Rabat Fes
4 29/05/12 Fes
5 30/05/12 Fes Erg Chebbi
6 31/05/12 Erg Chebbi Dades Vallei
7 01/06/12 Dades Vallei Ouarzazate
8 02/06/12 Ouarzazate Marrakesh
9 03/06/12 Marrakesh
10 04/06/12 Marrakesh
11 05/06/12 Marrakesh Amsterdam
You should have a look at the tinymce configuration options concerning the paste plugin.
Another option is to strip out all unwanted html tags and just use plain text: TinyMCE Paste As Plain Text

Resources