Learning how to scrape websites with Puppeteer
, it occurred to me, as javascript newbie, that the simplest way to work with certain dynamically generated sites would be to create a loop to cycle through some Div
's one by one, and to trigger actions based on their specific attributes (e.g., click all Div's in loop with `class=Clickable)
Most of the Puppeteer
examples online go through how to select page elements by certain names/classes, like in here, but not how to create such a loop that goes through a subportion of Div
's, and perform actions based on them.
Since I am new to Javascript, if someone would give me advice or pointers on how to do this, I would be extremely grateful.
Example: I want to scrape data from the bottom most layers of certain Div
's, in this case those with section=
some variant of the letter C, so I open the following slice of Div
's in the following way, with the plan to extract some data at the end,
<div class="Table" section="A">
<div class="Columns" id style="display: none;">
<div class="Table" section="B">
<div class="Columns" id style="display: none;">
## section "C" has been clicked by Puppeteer,
## and so indented part is what is expanded from class=Columns
<div class="Table" section="C">
<div class="Columns" id style>
## Next sub-section that needs to be gone through
<div class="Column" section="a">
<div class="Rows" id style="display: none;">
<div class="Column" section="b">
<div class="Rows" id style="display: none;">
## Repeating same process one layer deeper now
<div class="Column" section="c">
<div class="Rows" id style>
<div class="Subsection" section="i">
<div class="data" id style>
............
............
*loop keeps going*
I hope my use case is clearer now.