Image Src url extraction using ms access vba ie navigation - ms-access

I am using MS Access code for VBA IE navigation. I want to extract image link value from below mentioned html code but unable to extract image link value.
HTML code is given below:
<div class="product-image-vp-sub">
<div class="js-media-zoom-icons hide-content">
<div class="zoom product-zoom product-zoom-in js-zoom-in wmicon wmicon-zoom"></div>
</div>
<img itemprop="image" src="http://ll-us-i5.wal.co/dfw/dce07b8c-3eca/k2-_f47f1f48-69bb-4277-9009-6f7d3a63697a.v2.jpg" class="product-image js-product-image js-product-primary-image" data-asset-id="2A5BB9FEFACA4EA09290025ED003ACAE" data-zoom-image="" alt="...And The Earth Did Not Swallow Him">
</div>
VBA code is given below.
Set html = ie.Document
my_data1 = html.getElementsByClassName("product-image-vp-sub")
For Each Item In my_data1
href1 = Item.getElementsByTagName("img")(0)
href2 = href1.src
Next

Related

HTML data update for XML column with new value in SQL Server

I have some experience in XQuery to update the XML data. I have tried to use the same logic for the HTML data in SQL Server.
But not working as expected.
For example I have a XML column Value (actually HTML data) as below.
Declare #template xml = '<div>
<div id="divHeader">Congratulation<div id="Salutation">ravi</div></div><br/>
<div>From now you are a part of the Company<div id="cmpnyUserDetails"></div></div><br/>
<div id="clickSection">Please Click Here to Access Your New Features</div>
</div>'
and I would like change the html value od the div with ID "Salutation" to "New Value" and Append the href value to a valid link using the XQuery.
SET #template.modify('replace value of (//div[id=("Salutation")]/text())[1] with "New Value"')
SELECT #template AS data
But it's not working.
Can someone please suggest to me how to make it happen?
Thanks a ton in advance,
Ravi.
You were close. Notice the #id vs. your id
Example
SET #template.modify('replace value of (//div[#id=("Salutation")]/text())[1] with "New Value"')
select #template as data
Returns
<div>
<div id="divHeader">Congratulation<div id="Salutation">New Value</div></div>
<br />
<div>From now you are a part of the Company<div id="cmpnyUserDetails" /></div>
<br />
<div id="clickSection">Please Click Here to Access Your New Features</div>
</div>

Not sure what element I need to click in IE HTML for VBA?

So I have the following HTML code (I'm not super familiar with HTML so excuse the incorrect spacing):
<div class="section_heading">
<span class="section_anchor" id="ajax_result_table_link" data-label="vs. Pitchers"></span>
<h2>vs. Pitchers</h2>
<div class="section_heading_text">
<ul>
<i>Sorting only sorts the values in the table shown</li>
<li>Click a player to see each PA</li>
<li class="hasmore drophover">
<span href="javascript:void(0)">Share & more</span>
<div>
<div class="closer" role="button" aria-label="close this menu"></div>
<ul>
<li><button class="tooltip" id="share_on_ajax_result_table" tip="Use a customizable report creator that can<br>output HTML, CSV, or a shareable link.">Modify & Share Table</button>
</li>
<li><button class="tooltip" tip="Get a bit of widget code to emed this table on your site">Embed this Table</button></li>
<li><button class="tooltip" tip="Convert the table below to comma-separated values<br>suitable for use with excel">Get as Excel Workbook (experimental)</button><a id="dlink" style="display: none;"></a></li>
<li><button class="tooltip" tip="Export table as <br>suitable for use with excel">Get table as CSV (for Excel)</button></li><li><button class="tooltip" tip="">Strip Mobile Formatting</button></li>
From this URL: https://www.baseball-reference.com/play-index/batter_vs_pitcher.cgi?batter=mancitr01
I am trying to use VBA to download the Excel workbook (under the "Share & More" Dropdown), but I can't seem to be able to click the link. I've tried using get element by class and get element by ID but they don't seem to work. I'm guessing this HTML code is a little more advanced than I'm used to. I've been trying to click the ID "dlink" but I'm not sure if that is the end goal.
Any help or input would be appreciated.
EDIT:
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https://www.baseball-reference.com/play-index/batter_vs_pitcher.cgi?batter=mancitr01"
Wait 10
IE.document.getElementById("dlink").Click
Exit Sub
Set oElementCollection = IE.document.getElementsByClassName("section_heading_text")
For Each span In oElementCollection
If span.innerHTML = "Share & more" Then
span.ParentNode.Click
Exit For
End If
Next span
Exit Sub

How to extract innerText of "Who was your first employer? into Excel from the given HTML

<div class="ContainerFieldControlHoriz" style="width: 400px;">
<label title="Who was your first employer?" id="dnn_ctr1854_ChallengeQuestion_ChallengeQuestionCmnTextBox_ControlLabel">Who was your first employer?</label>
</div>
My code was
Set htmlsecurityquestion = htmldoc.getElementById("dnn_ctr1854_ChallengeQuestion_ChallengeQuestionCmnTextBox_ControlLabel")
Range("A1").Value = htmlsecurityquestion.innerText
but it is not working
You access this value through attributes collection, not through innerText. Your second line should be:
Range("A1").Value = htmlsecurityquestion.Attributes["title"].Value;

Web scraping using excel VBA

I am looking at an HTML code link below:
<h1 class="wer wer">
<a href="http://somelink.com" rel="bookmark" title="Permanent Link to Title of this page that covers some random topic">
Short title of this page...</a>
</h1>
I am currently using the below code to pull out innertext ("Short title of this page...")
For Each ele In .document.all
Select Case ele.classname
Case "wer wer"
RowCount = RowCount + 1
sht.Range("A" & RowCount) = ele.innertext
End Select
Next ele
How can I modify this code to pull out title ("Permanent Link to Title of this page that covers some random topic") and href ("http://somelink.com")?
Any help would be much appreciated. Thanks.
Select the element by its styling.
.document.querySelector("a[href=http://somelink.com]").innerText
a[href=http://somelink.com] is a CSS selector of first element with an a tag having href = 'http://somelink.com'.

get element id with vb

I have the following code in an aspx page:
<div id="objectList" style="overflow: auto; width:100px; display:block;
position:absolute;top:0px;left:0px;z-index:100;">
<div id="object8" class="object" title="">
<br>object8</div>
<div id="object2" class="objectSelect" title="">
<br>object2</div>
</div>
I am attempting to find the ID of the object that is selected, in this case object2. I am trying to do it in the codebehind with vb.net but I'm not sure how. Any help would be appreciated.
Add runat="server" to all of the <div> elements you wish to find out if they are selected or not, like this:
<div id="object8" class="object" title="" runat="server">
<div id="object2" class="objectSelect" title="" runat="server">
Now in code-behind you can loop through all of the <div> elements in the page and check the class attribute value, like this:
For Each item As Control In Me.Controls
' We have to look at all HtmlGenericControl, because
' there is no .NET control type for DIV
Dim theDiv As System.Web.UI.HtmlControls.HtmlGenericControl = TryCast(item, System.Web.UI.HtmlControls.HtmlGenericControl)
' Make sure the cast worked before we try to use the DIV
If theDiv IsNot Nothing Then
' Is the class name equal to objectSelect?
If theDiv.Attributes("class") = "objectSelect" Then
' Yes, this DIV is selected, do something here
End If
End If
Next