shahin
Active Member
I've written a macro to parse certain paragraphs embedded within "p" tag which is again within "article" tag container. If i only wish to parse the paragraph then running the code I can do so. However, I'm slightly confused about the relational structure of dom. So far I knew (considering the below html snippet) that if "article" tag is the parent then it has got 6 children which are [div,h1,div,div,div,div] accordingly. When i try to execute the commented out portion of code (which has been written using the relational structure), it no longer works. What I'm missing here? Thanks in advance.
The code:
Html elements (FYC):
Forgive me if I've addressed specific elements otherwise.
The code:
Code:
Sub demo()
Dim http As New InternetExplorer, html As HTMLDocument
Dim r As Long, elem As Object
With http
.Visible = False
.navigate "http://themakeupblogger.com/makeup/"
Do Until .readyState = READYSTATE_COMPLETE: Loop
Set html = .document
End With
' Set elem = html.getElementsByTagName("article")(0).LastChild.PreviousSibling.getElementsByTagName("p")
' [A1].Value = elem(0).innerText '''It doesn't work
Set elem = html.getElementsByTagName("article")(0).getElementsByTagName("div")(3).getElementsByTagName("p")
[A1].Value = elem(0).innerText '''It works
End Sub
Html elements (FYC):
Code:
<article id="entry-13600" class="entry post-13600 post type-post status-publish format-standard has-post-thumbnail hentry category-makeup tag-memorial-day tag-summer-beauty">
<div class="entry-meta entry-meta-top">
<p class="entry-categories">
<a href="http://themakeupblogger.com/makeup/" rel="category tag">Makeup</a> </p>
</div>
<h1 class="entry-title">
<a href="http://themakeupblogger.com/10-memorial-day-beauty-essentials-belong-beach-bag/">10 Memorial Day Beauty Essentials That Belong In Your Beach Bag</a>
</h1>
<div class="entry-meta entry-meta-bottom">
<time class="entry-date" datetime="2017-05-25T10:56:16+00:00">May 25, 2017</time>
<a href="http://themakeupblogger.com/10-memorial-day-beauty-essentials-belong-beach-bag/#comments" class="entry-comments-no">3 Comments</a>
</div>
<div class="entry-featured">
<a href="http://themakeupblogger.com/10-memorial-day-beauty-essentials-belong-beach-bag/">
<img width="665" height="442" src="https://i1.wp.com/themakeupblogger.com//nas/content/live/kimdo/images/2017/05/beach.jpg?fit=665%2C442" class="attachment-large size-large wp-post-image" alt="" srcset="https://i1.wp.com/themakeupblogger.com//nas/content/live/kimdo/images/2017/05/beach.jpg?w=1150 1150w, https://i1.wp.com/themakeupblogger.com//nas/content/live/kimdo/images/2017/05/beach.jpg?resize=400%2C266 400w, https://i1.wp.com/themakeupblogger.com//nas/content/live/kimdo/images/2017/05/beach.jpg?resize=903%2C600 903w, https://i1.wp.com/themakeupblogger.com//nas/content/live/kimdo/images/2017/05/beach.jpg?resize=665%2C442 665w, https://i1.wp.com/themakeupblogger.com//nas/content/live/kimdo/images/2017/05/beach.jpg?resize=391%2C260 391w" sizes="(max-width: 665px) 100vw, 665px" data-attachment-id="13604" data-permalink="http://themakeupblogger.com/10-memorial-day-beauty-essentials-belong-beach-bag/beach/" data-orig-file="https://i1.wp.com/themakeupblogger.com//nas/content/live/kimdo/images/2017/05/beach.jpg?fit=1150%2C764" data-orig-size="1150,764" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"1"}" data-image-title="beach" data-image-description="" data-medium-file="https://i1.wp.com/themakeupblogger.com//nas/content/live/kimdo/images/2017/05/beach.jpg?fit=400%2C266" data-large-file="https://i1.wp.com/themakeupblogger.com//nas/content/live/kimdo/images/2017/05/beach.jpg?fit=665%2C442"> </a>
</div>
<div class="entry-content">
<p>Me Oh My Girl Halcyon beach days are here again! Even though the energy of summertime is about being wild and free and comfortable in your skin, it doesn’t necessarily mean you have to ditch makeup and hair altogether. But paring down and perfecting your seaside-beauty routine means less distractions from what really matters: soaking […]</p>
</div>
<div class="entry-utils group">
<a href="http://themakeupblogger.com/10-memorial-day-beauty-essentials-belong-beach-bag/" class="read-more">Continue Reading</a>
</div>
</article>
Forgive me if I've addressed specific elements otherwise.