How to scrape mailto from following page using VBA - html

i am trying to scrape mailto (href) from a html file, but i am unable to "hit" it.
Any advice is welcome.
<div class="exhibitor-contact">
<div class="col">
<h3>
whatever </h3>
<p>
MLW <br /> whatever<br /> 75008 Paris - France </p>
<p>
<a class='inverse-a-span' href='#tel' id='tel' onclick="return xt_click(this,'C', xtn2, xtpage.replace(/\w*$/, 'exhibitor::tel').replace(/^Exhibitors::/, ''), 'A')">Show Phone Number</a><span style='display:none;'>whatever</span><br /> Send an Email<br /> </p>
</div>
</div>
</section>
Code:
Set my_data = IE.Document.getElementsByClassName("anyclass")
Set mail = IE.Document.getElementsByTagName("a")(0) ActiveSheet.Cells(i, 2).Value = mail.href

Use a css attribute = value selector with ^ starts with operator
Debug.Print ie.document.querySelector("[href^='mailto:']").href

Related

Embed image into outlook email

I want to embed images saved in local directory into an outlook email. Have defined a function to do that and also added the html according. However, the image doesn't come up. Not an issue with the file path as I've already checked that it's working. What did I do wrong?
def Emailer(text, subject, recipient, cc):
import win32com.client as win32
import os
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = recipient
mail.CC = cc
mail.Subject = subject
mail.HtmlBody = text
mail.Display(True)
MailSubject = "Daily Report for " + date_slash
MailInput ="""
<div>
<img src={}></img>
</div>
<div>
<p>
</div>
<div>
<img src={}></img>
</div>
<div>
<p>
</div>
<div>
<img src={}></img>
</div>
<div>
<p>
</div>
<div>
<img src={}></img>
</div>
<div>
<p>
</div>
<div>
<img src={}></img>
</div>
"""
MailInput = MailInput.format(date_slash, sum_path, ovdv_path, cot_path, rub_path ,pnl_path)
MailRecipient ="xxx#yyy.com;"
MailCc = "xxx#yyy.com;"
A remote recipient cannot obviously see files from your machine.
You need to add images as attachments (Attachment = MailItem.Attachments.Add) and set the PR_ATTACH_CONTENT_ID MAPI property to the value used in the <img> tag (e.g., <img src='cid:MyTestId'>) using Attachment.PropertyAccessor.SetProperty:
Attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", "MyTestId")

Dynamically Inject new HTML into a web page and be able to access any new DOM elements that are in the "new" injected HTML

I found this link that suggested injecting a table into a div.
enter link description here
Here is an example of new HTML that I want to inject:
<br />
<br />
<LSz class='LineSpaceDouble'>
Hi, <p class='FIRST_NAME'> </p> <br><br>
Hi <p class='FIRST_NAME'> </p>, my name is <p class='MYNAME'> </p> .
More Text.<br>
</LSz>
<br />
<label for='PBirthDate'>Primary Birthdate:</label>
<input id='PBirthDate' class='input100' type='text' name='PBirthDate' placeholder='mm/dd/yr' size='10'>
<span class='focus-input100'></span>
<br />
Here is my current jq code that does the injection:
var S = J;
$(S).appendTo('#Script_Displayed');
J holds HTML text to be injected.
and Script_Displayed is the id of the div
THAT works -- in that the "text" is indeed injected into the web page where the div is located.
My problem is when I attempt to change a value:
var Z = document.getElementsByClassName('FIRST_NAME');
Z.innerHTML = "Anthony";
The new innerHTML value does not appear on the web page.
What Can I do to make these changes visible?
The function getElementsByClassName returns a collection of elements, not a single element. So this won't work by default:
Z.innerHTML = "Anthony";
Instead, loop over the collection to assign the innerHTML value to each element in the collection:
var Z = document.getElementsByClassName('FIRST_NAME');
for (let el of Z) {
el.innerHTML = "Anthony";
}
Hi, <p class='FIRST_NAME'> </p> <br><br>
Hi <p class='FIRST_NAME'> </p>, my name is <p class='MYNAME'> </p> .
More Text.<br>

Encode .ico in HTML Application (.hta) File

UPDATE: I changed the image displaying on my page to an encoded version, instead of referencing the external image. I was able to put my image into a Base64 converter, and then copy and paste the string version of the image into the file (represented by ~~~ in my code below). This worked fine. Is there a similar method for encoding the icon?
Problem: I have a HTML Application file (.hta) that I've created. To make the user experience more customized I would like to change the icon for the taskbar (and maybe the actual file when looking at it in the file explorer or on SharePoint). The reason I want to encode the image instead of using a file is because when I try to use a network file, it takes a 'long' time to open the .hta file and I know this will annoy my end users. It is a basic site with links to open template files that we use frequently, the purpose is to open a copy of the most recent template so we make sure everyone is using the most current templates and knows where all of the tools we use are located. I've researched this quite a bit and I can't seem to find a solution that works for me.
What I've Tried:
I've tried the "trick" where I use the Command Prompt to copy the .ico file to the .hta file. This does change the icon but displays a bunch of nonsensical text at the top of my page above all of my content. If someone has a solution for removing this, that works. Unless this is not a stable solution...
I've also tried converting my image to Base64 and using that when declaring the ICON in < HTA:APPLICATION ... />, similar to encoding for < img >, but it didn't work for me. When I tried, nothing happened.
Additional Comments: I'm OK with any solution really, as long as the image is encoded and it is stable.
Basic Structure of Working File (UPDATED):
<!DOCTYPE html>
<html>
<HTA:APPLICATION ID = "oMyApp" APPLICATIONNAME = "MyApp" ICON = "path" BORDER = "thick" CAPTION = "yes" SHOWINTASKBAR = "yes" SINGLEINSTANCE = "yes" SYSMENU = "yes" WINDOWSTATE = "maximize" />
<head>
<title> My App </title>
<link rel = "icon" href = "path">
<link rel = "sytlesheet" type = "text/css" href = "StyleSheet.css">
</head>
<body> <div class = "content">
<div class = "Title">
<img src = "data:image/png;base64,~~~" alt = "icon" />
<strong> My App </strong>
</div>
<div class = "main">
<div class = "column">
<div class = "box">
File Name <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<div class = "box">
File Name <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<div class = "box">
File Name <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<br><br>
</div>
<div class = "column">
<div class = "box">
File Name <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<div class = "box">
File Name <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<div class = "box">
File Name <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<br><br>
</div>
<div class = "column">
<div class = "box">
File Name <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<div class = "box">
File Name <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<div class = "box">
File Name <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<br><br>
</div>
<div class = "column">
<div class = "box">
File Name <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<div class = "box">
File Name <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<div class = "box">
File Name <br>
<strong> Instructions </strong> <br>
<em> Description of File </em>
</div>
<br><br>
</div>
</div>
<div class = "Footer">
<em> Comment to Users </em>
</div>
</div> </body>
</html>
Please Help

Invoke click in a webbrowser element

I have a webbrowser control (name: WB) in my VB .net form.
I have loaded a webpage in webbrowser. Here is the sample html:
enter code here
<script type="text/javascript">
Sys.WebForms.PageRequestManager._initialize
('ctl00$ContentPlaceHolder1$ScriptManager1', 'form1',
['tctl00$ContentPlaceHolder1$UpdatePanel1',
'ContentPlaceHolder1_UpdatePanel1'], [], [], 90, 'ctl00');
</script>
<div class="row">
<div class="control group alternating">
<h2>Results</h2>
<div id="ContentPlaceHolder1_UpdatePanel1">
<div class="row">
<a id="ContentPlaceHolder1_Repeater1_LinkButton1_0"
href="javascript:__doPostBack('
ctl00$ContentPlaceHolder1$Repeater1$ctl00$LinkButton1','')">
<strong>A. Bleakley Chandler, MD</strong></a><br />
Georgia Medical College<br />Augusta, GA, USA
</div>
<div class="row">
<a id="ContentPlaceHolder1_Repeater1_LinkButton1_1"
href="javascript:__doPostBack('
ctl00$ContentPlaceHolder1$Repeater1$ctl01$LinkButton1','')">
<strong>A. Kyle Mack, MD</strong></a><br />
Ann and Robert H. Lurie Children's Hospital of Chicago<br />
</div>
<div class="row">
<a id="ContentPlaceHolder1_Repeater1_LinkButton1_2"
href="javascript:__doPostBack('
ctl00$ContentPlaceHolder1$Repeater1$ctl02$LinkButton1','')">
<strong>A. Lawrence Ossias, MD</strong></a><br />
Mount Sinai NYC<br />
</div>
<div class="row no-shading">
<div class="pagination-arrows right">
<span>
1 of 100</span>
<a id="ctl00_ContentPlaceHolder1_Repeater1Prev" class="aspNetDisabled ir
prev">prev</a>
<a id="ctl00_ContentPlaceHolder1_Repeater1Next" class="ir next"
href="javascript:__doPostBack('
ctl00$ContentPlaceHolder1$Repeater1Next','')">next</a>
</div>
</div>
</div>
Now I want to click on the first element of Repeater control. My InvokeMember code:
Dim pLink As HtmlElement = WB.Document.GetElementById
("ContentPlaceHolder1_Repeater1_LinkButton1_0")
pLink.InvokeMember("click") 'doesn't work
But due to some unknown reason, the click doesn't fire inside this repeater control. Other links in the page works fine with "invokemember("click")"
like the following one :
Dim pLink As HtmlElement = WB.Document.GetElementById
("ctl00_ContentPlaceHolder1_Repeater1Next")
pLink.InvokeMember("click") 'Works fine..
I tried GeckoFx browser control (geckoanchorelement.click), this did not work. I also tried to send MouseClick thru postmessage api - this also failed.

Extract Specific Text from Html Page using htmlagilitypack

Hey most of my issue has been solved but i have little problem
This is Html
<tr>
<td class="ttl">
</td>
<td class="nfo">- MP4/H.263/H.264/WMV player<br />
- MP3/WAV/еAAC+/WMA player<br />
- Photo editor<br />
- Organizer<br />
- Voice command/dial<br />
- Flash Lite 3.0<br />
- T9</td>
</tr>
Currently i am using this code provided by Stackoverflow User
var text1 = htmlDoc.DocumentNode.SelectNodes("//td[#class='nfo']")[1].InnerHtml;
textBox1.Text = text1;
know problem its is getting all text
with <br>
how i can remove <br> from it and put , between them
its should look like this
MP4/H.263/H.264/WMV player,- MP3/WAV/еAAC+/WMA player,- Photo editor,- Organizer,- Voice command/dial,- Flash Lite 3.0,- T9
Also how to get this
<div id="ttl" class="brand">
<h1>Nokia C5-03</h1>
<p><img src="http://img.gsmarena.com/vv/logos/lg_nokia.gif" alt="Nokia" /></p>
</div>
i am trying this
var text41 =
htmlDoc.DocumentNode.SelectNodes("//div
id[#class='brand']")[0].InnerText;
i get invalid token error
i only want C5-03 without nokia text
You can simply use a string.Replace("<br />", ""); to remove the <br /> tags.
Better yet, use the InnerText instead of InnerHtml, so no HTML comes through:
var text1 = htmlDoc.DocumentNode.SelectNodes("//td[#class='nfo']")[1].InnerText;
If you really want to replace all <br /> tags with a , you will indeed need to use Replace:
text1.Replace("<br />", ",");
To select the value in the <H1> tag, you could use:
var text42 = htmlDoc.DocumentNode.SelectNodes("//div[id='ttl']"/h1)[0].InnerText;