<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Diska Armeina on Medium]]></title>
        <description><![CDATA[Stories by Diska Armeina on Medium]]></description>
        <link>https://medium.com/@diskaarmeina?source=rss-2184b64a50a7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uTjTTvKyASYZSjvEmG88dA.jpeg</url>
            <title>Stories by Diska Armeina on Medium</title>
            <link>https://medium.com/@diskaarmeina?source=rss-2184b64a50a7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 00:29:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@diskaarmeina/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Naive Bayes in term of ”Just Do it” or “Do it Scared”]]></title>
            <link>https://diskaarmeina.medium.com/naive-bayes-in-term-of-just-do-it-or-do-it-scared-0e650ca764ec?source=rss-2184b64a50a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/0e650ca764ec</guid>
            <category><![CDATA[naive-bayes]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Diska Armeina]]></dc:creator>
            <pubDate>Sun, 21 Sep 2025 09:54:11 GMT</pubDate>
            <atom:updated>2025-09-21T09:54:11.587Z</atom:updated>
            <content:encoded><![CDATA[<p>A few days ago, while scrolling through my phone gallery, I found a screenshot I had saved back on June 18, 2022. Honestly, I don’t really remember whether it came from Twitter (I mean, X) or LinkedIn, since it was in my Downloads folder. So, apologies that I can’t give proper credit. But thank you to whoever originally shared it, because even three years later, it still matters to me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FF9-Yr2uWFgk4vL8mrKsjw.jpeg" /><figcaption>Image saved on June 18, 2020 9:14 PM</figcaption></figure><p>I even reposted it on my WhatsApp story, and maybe some of you noticed. Interestingly, this image also reminded me of something from classification models. And then I thought: why not interpret this using one of the well-known discriminative models, like Naive Bayes?</p><h3><strong>Discriminative vs. Generative Models</strong></h3><p><strong>Discriminative models</strong> are models that focus on the decision boundary. They solve problems by separating, or “discriminating” data into classes based on the training and target data provided. Simply “this” or “that”.</p><p>For example, imagine you ask your friend to bring you a Purbolinggo avocado. You only need to distinguish whether it is a Purbolinggo avocado or not. You don’t really dig deeper into whether the avocado was actually planted and grown in Purbolinggo, or if it’s simply available in a supermarket, possibly imported from its origin in South America?</p><p>The second case reflects what we call a <strong>Generative model</strong>, where we try to understand where the data comes from and what its conditional probability distribution looks like.</p><p>Back to our case, with all the data given, let’s interpret the chart using a classification model. There are several options we could apply, such as Decision Tree, Random Forest, KNN, or Naive Bayes. For this example, I’ll use Naive Bayes.</p><p>Why Naive Bayes? Because Bayes’ Theorem is one of the foundational principles behind both generative and discriminative approaches in machine learning.</p><p>Let’s go back to Bayes’ Theorem itself and see how Naive Bayes applies it to solve a classification problem.</p><h3><strong>Bayes’ Theorem</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*_L4ZL8rkEHcjyriJoCXccQ.png" /><figcaption>Bayes’ Theorem [1]</figcaption></figure><p>where,</p><ul><li><strong>P(z)</strong> = the initial probability of z(<em>prior</em>)</li><li><strong>P(X|z)</strong> = the probability of seeing X if z is true (<em>likelihood</em>)</li><li><strong>P(z)</strong> = the overall probability of z (<em>evidence</em>)</li><li><strong>P(z|X)</strong> = the updated probability of z given that X happened (<em>posterior</em>)</li></ul><p>Ok, let’s imagine if someone gives you $10,000 . <em>What’ll the chance you feel happy?</em></p><ul><li><strong>P(Happy)</strong>: probability that someone feels happy in general (say 50%).</li><li><strong>P(Money|Happy)</strong>: probability that someone who is happy receives $10,000 (say 80%)</li><li><strong>P(Money)</strong>: probability that a random person receives $10,000 (say 10%)</li><li><strong>P(Happy|Money)</strong>: probability that a person is happy <strong><em>given that </em></strong>they received $10,000.</li></ul><p>So, if we implied bayes theorem we got P(Happy|Money) = (0.80×0.50)/0.1 = 4. Since probabilities can’t be greater than 1, this actually means it’s <strong>almost certain (~100%)</strong> the person will be happy if they get $10,000! For sure!</p><p>Of course, Money is not the one and only thing make us happy. Therefore, there will be other variables defining happiness. So let’s call them as <em>Xi.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*3acPfSq1FWUhYxZGzczE5Q.png" /></figure><p>Naive bayes assumes all variable is independent so that the formula could be expanded as follows [2].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*OvubuDhxn2Nfqckh-3BxUw.png" /></figure><p>Since <em>X </em>is constant given input, so result this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*F1gbNTJeKdIaggdfoKPMQg.png" /></figure><p>Ok, we’ve got the theory, how to implement to this case?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FF9-Yr2uWFgk4vL8mrKsjw.jpeg" /></figure><p>Ok, let’s define the classes: Target Class (z) as “Do it” and “Not do it” and features <em>Xi </em>as “Want” and Scared”.</p><p><strong>Prior Probability: </strong>We assume that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/284/1*PVyuAfnaBHNCxiw36RM81w.png" /></figure><p>From the diagram, we clearly see that all the statement ends with “Do it” so we can set that P(DoIt) &gt; P(NotDoIt).</p><p><strong>Likelihood Probability:</strong></p><p>If the person wants something (Want = yes) and also feels scared (Scared = yes), the probabilities can be expressed as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*hNJ18CHfFQ0nW9mz-UULTQ.png" /></figure><p><strong>Posterior Probability:</strong></p><p>Next, we compare:</p><ul><li>For Z = DoIt</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*yUBvm8jWpalKu-G2FPe9ug.png" /></figure><ul><li>For Z = NotDoIt</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*SWLKMvd9Qjx4ML02gvDi-g.png" /></figure><p>From the diagram, all paths still lead to <em>Do It</em>. So we conclude:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*jVaQJHBYG4KBcHNHbYEItg.png" /></figure><p>In short: even if you want something but feel scared, <strong>just do it anyway!</strong></p><p>That’s the fun of connecting a motivational quote with probability theory. You can also try applying Naive Bayes to a real dataset and run the numbers yourself!</p><p>Thanks for following along this random yet nerdy thought experiment! :D</p><h3><strong>Reference:</strong></h3><p>[1] Geron, A. Machine Learning with Scikit Learn</p><p>[2] Scikit-Learn Naive Bayes Documentation: <a href="https://scikit-learn.org/stable/modules/naive_bayes.html">https://scikit-learn.org/stable/modules/naive_bayes.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0e650ca764ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BTN Jakim Event: Short Stories Behind the Numbers]]></title>
            <link>https://diskaarmeina.medium.com/btn-jakim-event-short-stories-behind-the-numbers-d86b18a6abe4?source=rss-2184b64a50a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/d86b18a6abe4</guid>
            <dc:creator><![CDATA[Diska Armeina]]></dc:creator>
            <pubDate>Sun, 17 Aug 2025 12:12:43 GMT</pubDate>
            <atom:updated>2025-08-18T01:13:45.479Z</atom:updated>
            <content:encoded><![CDATA[<p>This year brought two remarkable international running events — the LPS Half Marathon and the BTN Jakarta International Marathon (JAKIM), held just two weeks apart in June 2025. It’s fascinating to dive into the data, especially for those of you considering joining running events and curious about the performance thresholds among runners.</p><p>IYKYK, I’ve started my analysis on the LPS Marathon event in my LinkedIn post <a href="https://www.linkedin.com/posts/diska-armeina_monas-lps-hm-2025-activity-7345048916913999872-o6E3?utm_source=share&amp;utm_medium=member_desktop&amp;rcm=ACoAAB2qerMB9P7758DcLIzc1CI7g_7FUH3jEjc">here</a>. I know it’s been over a month since the event, hehe. Honestly, with all the hectic stuff going on me lately, the BTN Jakim data has turned out to be a bit more challenging.</p><p>Besides, the number of participants is 6 times bigger than the LPS runners, that is about more than 30,000 runners! Unfortunately, the result page doesn’t show detailed data on their countries of origin. However, according to BTN Jakim’s Instagram, runners from 51 countries took part. Wow!</p><p>When it comes to data scraping, it really depends on the website structure. It’s lucky if both events have the same structure. For LPS HM, the data is all on one page, so we could easily scrape everything: from the runners’ names, gender, BIB, finished times, to the cut off points.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yUkJu8DmzLRBpgbpgta6cQ.png" /><figcaption>LPS Half Marathon’s Result Web</figcaption></figure><p>However for BTN Jakim, the time splits are on a different page, so we need to click through for the details. Yeah, it definitely takes much much way longer… maybe I should consider getting a new PC?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TeoQljO0SKoNMLkTnls8Jw.png" /><figcaption>BTN Jakim’s Result Web</figcaption></figure><p>And around 80% of this project went into scraping and getting the data ready.</p><p>Before we jump into the results, note that this analysis includes some small data adjustments due to anomalies.</p><ul><li><strong>First one</strong>, the data was last updated on August 09, 2025 so maybe you’re noticed there’s data missing or different data updated since the first time race result was coming up.</li><li>There’s some missing data and yea, this is common happened during the race. Maybe the chip was error to record some data split. Therefore, there are missing some split data even though the runner finished, or the finished time is missing but gun time exists.</li><li>The anomalies also happened when the runners are identified as DNF (Did not Finish) while some split data were still recorded. I handled it by still leading to the finisher category and ignoring split data.</li><li>I also didn’t scrape all the detailed data due to limitations and to avoid an overly long scraping process. To fill some gaps, I created new features myself, such as calculating the runners’ pace. So you might notice slight differences compared to the real data.</li></ul><p>So, finally, here’s the result. BTN Jakim held the event with several categories: 10K, Half Marathon, and Marathon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*yV5Cr_VEoqAtL7S6u5ZH4g.png" /><figcaption>Category Distribution</figcaption></figure><p>Overall, the runners joined 10K category about 47.8% and most participant of this events came from Men, about 64%. All participant successfully completed the race with finish rate 91.3%. A few registered runners, however, didn’t make it to the finish due to DNS (Did Not Start), DNF (Did Not Finish), or disqualification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/175/1*0ZwxJwIh6y2FZdp0t6ZOfw.png" /><figcaption>Runners’ Status</figcaption></figure><p>On average, the 10k runners wrapped it up in about 1:28:06 (pace ~8.8 min/km). The highlight goes to Pandu Sukarya (<a href="https://www.instagram.com/p/DLmgFg_vT0j/">https://www.instagram.com/p/DLmgFg_vT0j/</a>, who blazed through the course and finished first in just 00:31:35 (that’s sub 3 pace!)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*4_1XW-XQIcXdrAodAGxoFw.png" /><figcaption>Overall 10K performance by Gender</figcaption></figure><p>Overall, participation in the 10K category was fairly balanced between men and women. The men wrapped up their 10K race in under 90 minutes.</p><p>From the boxplot below, the female median pace is centered around 8–9 min/km, with the bulk of runners finishing steadily in this band. The middle 50% fall in the 8–10 min/km range, showing consistency among most finishers. A few standout runners achieved fast paces near 4 min/km, highlighting strong performances.</p><p>Meanwhile, most male runners are clustered in the 7–10 min/km range (the box, or middle 50%), with some exceptional performances reaching speeds as fast as ~3 min/km.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*OD183L0KpxHrluEywQlbvQ.png" /></figure><p>If you’re still on the fence about joining a race because you feel your pace is ‘too slow,’ don’t worry. The results here can be a great benchmark and as you can see, plenty of participants took it easy, ran at a slower pace, or simply joined in for fun. There’s always room for everyone on race day!</p><p>Ok, Let’s kick things off with the Half Marathon category. Out of the 30K BTN Jakim participants, around 38% (about 11,694 runners) joined the Half Marathon with 10,979 finished runners, which is twice the number of participants in the LPS Half Marathon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*yyrk1Q4mQdHFKlcw5Wtleg.png" /><figcaption>Total Runners for each Cut Off Points</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*EyvZT1DLSZBbtPik-3Ofyg.png" /><figcaption>HM Performance Result between BTN Jakim and LPS HM</figcaption></figure><p>For Both, LPS HM and BTN Jakim, 60%-70% participant dominated by men. Looking at the table above, BTN Jakim’s female runners averaged 2:50:49, just a few minutes behind the 2:44:15 average at LPS Half Marathon. It’s still an impressive showing given the much larger field and global participation. The fastest woman at BTN Jakim crossed in 1:14:45, not far from LPS’s 1:11:24.</p><p>For the men, BTN Jakim’s average time was 2:36:58, only about six minutes shy of LPS’s 2:30:42. BTN Jakim’s quickest male finished in 1:05:00, showing strong competition close to LPS’s top time of 1:02:55.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*zGeZRRfYjIVhtIEjHkSyLQ.png" /><figcaption>BTN Jakim Detail Finished Time Performance break by Gende</figcaption></figure><p>Interestingly, the middle-performing runners at BTN Jakim (those in the 25%–50% range) recorded finish times that are comparable to the overall average results at LPS Half Marathon. With even the mid-pack runners, they’re performing at a level close to the full field in LPS HM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/983/1*UvofCCzX7Gnn4MmimbSbrQ.png" /><figcaption>Pace Distribution</figcaption></figure><p>The slight difference in pace ranges between BTN Jakim and LPS could be influenced by two main factors. First, BTN Jakim, with over 30K participants worldwide, likely had a higher proportion of recreational runners which naturally stretches the slower end of the pace distribution. Second, BTN Jakim’s longer cut-off time may have encouraged more participants to join and complete the race, further widening the overall pace range.</p><p>Looking at both LPS and BTN Jakim, each event offers its own story, from the competitive edge and tighter pace range of LPS to the larger, more diverse field and broader range of BTN Jakim. Together, they show a picture of how different race environments can shape performance. I hope these insights can be useful for those preparing for their first half marathon, looking to improve their performance, or setting a new target, off course for me and our next race!</p><p>Ok let’s move on to the Marathon category. This one’s definitely not for beginners… lol. The finish rate is very high about 98%. The real struggle starts after 30 km, which is typical in marathons as runners hit the endurance wall. The largest drops appear between KM36.6 — KM39.5, where dozens of runners stopped.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*nPzjO0G9v9fRJDeqqfBjug.png" /></figure><p>The marathon saw a much larger male participation compared to female runners. Both groups showed a wide performance range, from sub-2:40 elites to 7-hour finishers, reflecting the mix of competitive and recreational runners. The average pace (7.3–7.8 min/km) suggests that for many participants, the marathon was about endurance and completion, not just speed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*CsppEnIxMqu4L4xCOZR82g.png" /></figure><p>For Male Marathon Finishers, the middle 50% (IQR) are spread from about 6.5 to 8.2 min/km, meaning most finishers cluster in this steady range. Some standout runners clocked very fast paces near 3–4 min/km, typical of elite-level marathoners. Meanwhile A few female outliers reached impressive speeds near <strong>4 min/km</strong>, showing strong performances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*4C38wiCwcvIWQ6PHlKDHeA.png" /></figure><p>At the start (3.8 km), everyone is still relatively fresh, with faster paces around 6.5–6.8 min/km. By 10 km, there’s a small dip (slower pace), which could be due to crowding, aid stations, or early pacing adjustments.</p><p>From 15 km to ~25 km, the pace stays fairly stable, meaning most runners were still maintaining control. After the 30 km mark, the pace starts climbing steadily — a sign of fatigue and the classic “marathon wall.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*ADD1PsYCAR5EJ8T139dZyQ.png" /></figure><p>Wrapping up the BTN Jakim race, it’s clear that this event brought together runners of all levels. The data shows how diverse the experiences were: some pushed their limits, some paced steadily, and others just wanted to cross the line with a smile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K4aHIazC3s0hawmruPvF3g.png" /><figcaption><a href="https://jakim.id/galeri_2025">https://jakim.id/galeri_2025</a></figcaption></figure><p>Hopefully these insights can inspire you to set your own goals, whether it’s your first 10K, Half Marathon or your next marathon. See you at the next starting line!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d86b18a6abe4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Starting data scrapping using Selenium in Python: Instagram’s Comment (Part 2)]]></title>
            <link>https://diskaarmeina.medium.com/starting-data-scrapping-using-selenium-in-python-instagrams-comment-part-2-d21cacd7df5c?source=rss-2184b64a50a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/d21cacd7df5c</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-scrapping]]></category>
            <category><![CDATA[scrapping]]></category>
            <category><![CDATA[instagram]]></category>
            <dc:creator><![CDATA[Diska Armeina]]></dc:creator>
            <pubDate>Sun, 08 Jun 2025 13:58:53 GMT</pubDate>
            <atom:updated>2025-06-08T13:58:53.302Z</atom:updated>
            <content:encoded><![CDATA[<p>In Part 1, we prepared our weapon — Selenium and a bit of Python magic. Now in Part 2, it’s time to choose our target: the Instagram post we want to scrape! 🎯</p><p>Let the hunt begin!</p><pre>link_post = &#39;https://www.instagram.com/p/DIOG-3uMf_t/?igsh=dms2NzduODZ6N3c1/&#39;<br></pre><p>Ok, Next, try accessing the link using Selenium’s driver:</p><pre>driver.get(link_post)</pre><p>When scraping data, it’s important to understand how the website is structured — the layout and behavior of its UI. That way, we can adjust our code to extract exactly the data we want.</p><p>The driver will drive the link post into Instagram as follows. What can you see here? There’s a carousel Instagram content from @detiknewsofficial in collaboration with @detikcom, we can see the caption containing emoticon and related hashtag. We also can see likes number here, and some action buttons to give the like, comment, share and saves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*ZHK7hxTHsN2k7wuMm5Zzag.png" /></figure><p>Looking to the right, we can see the scroll bar to load more comments. If we scroll until the end of scroll bar, Instagram will automatically load more comments data. You’ll also notice comment replies, a like button for each comment, and other features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*0aYsfJjhSyWIGxffkudExQ.png" /></figure><p>Back to our goal, we want to scrap all the data comment. But first, we need to make sure all comments are loaded. Let’s start by identifying the scrollable element using your browser’s inspect tool, then include it in your Python code:</p><pre>scrollable_div = driver.find_element(By.XPATH, &#39;//div[contains(@class, &quot;x5yr21d xw2csxc x1odjw0f x1n2onr6&quot;)]&#39;)</pre><p>Since Instagram doesn’t give us a clear indicator when comments are fully loaded, we’ll implement a logic workaround.</p><pre>prev_count = 0<br>max_try = 32<br>counter = 0</pre><p>You can adjust max_try number if the post has exploded comments. Next, we activate the scrollable_div . The 1000 value is the scroll height in pixels — enough to trigger new comment loading.</p><pre>while True:<br>    driver.execute_script(&quot;arguments[0].scrollBy(0, 1000);&quot;, scrollable_div)<br>    time.sleep(1)</pre><p>You may experiment with the smaller or the higher number and if you find the difference, let me know!</p><p>Time Sleep here is to give a moment <strong>before</strong> they’ve had a chance to load a new comment. It also purpose for mimic human behavior, to avoid bot detecting or rate-limiting.</p><p>Ok, now, let’s collect the comments!</p><pre>    comments = driver.find_elements(By.XPATH, &#39;//span[@class=&quot;x1lliihq x1plvlek xryxfnj x1n2onr6 x1ji0vk5 x18bv5gf x193iq5w xeuugli x1fj9vlw x13faqbe x1vvkbs x1s928wv xhkezso x1gmr53x x1cpjm7i x1fgarty x1943h6x x1i0vuye xvs91rp xo1l8bm x5n08af x10wh9bi x1wdrske x8viiok x18hxmgj&quot;]&#39;)<br>    print(&quot;Total comments:&quot;, len(comments))</pre><p>You could find the path on Instagram’s path for the class. It possibly changes in the future as Instagram always has new updates features. Next, we check if new comments are still being loaded. If not, we increment the counter; if they are, we reset the counter to zero.</p><pre>    if len(comments) == prev_count:<br>        counter += 1<br>    else:<br>        counter = 0<br><br>    if counter &gt;= max_try:<br>        break<br><br>    prev_count = len(comments)</pre><p>Next, let’s do some data cleaning. The comment will be shown into a dataframe here.</p><pre>data = []<br><br>for i in range(2, len(comments)-1, 2): <br>    comment = comments[i].text<br><br> data.append({&#39;username&#39;: username})</pre><p>Taddaa! The comments are successfully scrapped.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*9djKmki0IJ8k3I5GJsEuyg.png" /><figcaption>Instagram comment scrapping result</figcaption></figure><p>Additionally, if we want to explore data, with the same way, we need to look for the path. For example here, I want to scrap the username and what time comment given.</p><p>Ok, let’s start with the username first. You know, scrapping data really depends on data structure. If we look at the result of comment path, we’ll get this one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*wCvy8GswaDGBKPTb0AtA1g.png" /></figure><p>Yeah, you’re right!</p><p>Instagram’s DOM structure for comments usually follows a pattern:</p><ul><li>Index 0 → content owner and caption</li><li>Index 1 → username of the first commenter</li><li>Index 2 → comment text</li><li>Index 3 → username of the second commenter</li><li>and so on…</li></ul><p>We have found the pattern right? So that, to get the username, we don’t necessarily add new path, just doing some code modification on this part.</p><pre>for i in range(2, len(comments)-1, 2): <br>    comment = comments[i].text<br>    username = comments[i+1].text<br><br> data.append({&#39;username&#39;: username, &#39;comment&#39;: comment})</pre><p>For the timestamp, we just use this one.</p><pre>driver.find_elements(By.XPATH, &#39;//time&#39;)</pre><p>It look simple right? yeah, that’s because each comment’s time is usually stored in a &lt;time&gt; element like:</p><pre>&lt;time datetime=&quot;2025-06-08T14:03:00.000Z&quot;&gt;1h&lt;/time&gt;</pre><p>Let’s convert the UTC time to Jakarta local time:</p><pre>timestamps = []<br><br>jakarta = pytz.timezone(&#39;Asia/Jakarta&#39;)<br>  <br>for t in times:<br>        try:<br>            utc_time = datetime.fromisoformat(t.get_attribute(&#39;datetime&#39;).replace(&#39;Z&#39;, &#39;+00:00&#39;))<br>            local_time = utc_time.astimezone(jakarta)<br>            timestamps.append(local_time.strftime(&#39;%Y-%m-%d %H:%M:%S&#39;))<br>        except:<br>            timestamps.append(None)</pre><p>Let’s now compile all three pieces of data — username, comment, and comment time — into a final DataFrame:</p><pre>for i in range(2, len(comments)-1, 2):  # MULAI dari index ke-2<br>    comment = comments[i].text<br>    username = comments[i+1].text<br>        <br>    comment_time = timestamps[i//2] if i//2 &lt; len(timestamps) else None<br>    data.append({&#39;username&#39;: username, &#39;comment&#39;: comment, &#39;comment_time&#39;: comment_time})<br><br>df = pd.DataFrame(data)</pre><p>And that’s it — all the comments are yours now!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*zUcFI0Rnrgv-OeRcmhud5w.png" /></figure><p>Hope you enjoyed the ride as I did. Catch you in the next one!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d21cacd7df5c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Starting data scrapping using Selenium in Python: Instagram’s Comment (Part 1)]]></title>
            <link>https://diskaarmeina.medium.com/starting-data-scrapping-using-selenium-in-python-instagrams-comment-part-1-42f5edd7dca2?source=rss-2184b64a50a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/42f5edd7dca2</guid>
            <category><![CDATA[data-scraping]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[instagram]]></category>
            <dc:creator><![CDATA[Diska Armeina]]></dc:creator>
            <pubDate>Wed, 23 Apr 2025 04:49:10 GMT</pubDate>
            <atom:updated>2025-04-23T04:49:10.315Z</atom:updated>
            <content:encoded><![CDATA[<p>Nowadays, we’re flooded with all kinds of news — from politics and economics to the latest K-drama actor scandals LOL. These topics quickly become viral, and if we scroll through Instagram, we’ll see tons of posts and even more comments where people share their thoughts.</p><p>Reading through all those comments could be fun (for me) — it gives us a peek into how people really feel — but let’s be honest, who has the time to scroll through hundreds (or thousands) of them?</p><p>Out of curiosity, I started wondering: <em>what if we could grab all that comment data and summarize what people are talking about?</em></p><p>That’s what led me to data scraping with Selenium in Python — and in this post, I’ll walk you through how I got started.</p><p><strong><em>Why Selenium instead of an API?</em></strong></p><p>API may be faster and cleaner, but not every website gives you access to one. Some require authentication, have strict usage limits, or even need special approval to use their official API.</p><p>That’s where Selenium comes in — although, let’s be honest, it sits in a bit of a legal gray area. It really depends on <strong>how</strong> you use it and <strong>what</strong> kind of data you’re scraping.</p><p>In my case, I’m scraping <strong>public data</strong> — Instagram comments that are visible to everyone. Doing it for fun, as a small personal experiment or educational needs, that’s generally okay.</p><p>But yeah, it’s important to be careful. You can’t go too hard and overload the website — there are request limits, and we should respect that.</p><p>Ok, let’s setting up the environment! Here some parts that we will be discussed today.</p><ul><li>Prepare your Python and Install Selenium</li><li>Set up Web Driver</li><li>Instagram login</li><li>Find the path to scrap</li></ul><p>It might be little bit longer, but let’s begin!</p><p><strong>Install Selenium.</strong> Simply running install code. Make sure it successfully installed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*suaElfAhqEqLrw0Bk47zWQ.png" /><figcaption>Selenium successfully installed</figcaption></figure><p><strong>Prepare your python and set up Web Drive.</strong></p><p>For web driver, you have some options what browser you used, these references help you to find it. Your web driver have to match with your browser version.</p><ul><li>Chrome : <a href="https://developer.chrome.com/docs/chromedriver/downloads">https://developer.chrome.com/docs/chromedriver/downloads</a></li><li>Edge : <a href="https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/?form=MA13LH">https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/?form=MA13LH</a></li><li>Firefox, using geckodriver : <a href="https://github.com/mozilla/geckodriver/releases">https://github.com/mozilla/geckodriver/releases</a></li></ul><p>For this time, I will use Chrome Driver.</p><pre>browser = webdriver.Chrome(&#39;YourLocalWebDriverPath&#39;)</pre><p>Luckily, there’s a library called webdriver_manager that makes life easier. It automatically downloads the correct version of web driver that matches your installed browser. So you don’t have to manually download, extract, or set the path yourself — it just works. This is also available for Firefox, Chrome, and Edge.</p><pre>from selenium import webdriver<br>from webdriver_manager.firefox import GeckoDriverManager #for Firefix<br>from webdriver_manager.microsoft import EdgeChromiumDriverManager #for Edge<br>from webdriver_manager.chrome import ChromeDriverManager #for Chrome<br><br>driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())<br>driver = webdriver.Edge(executable_path=EdgeChromiumDriverManager().install())<br>driver = webdriver.Chrome(executable_path=ChromeDriverManager().install())</pre><p>Since we want to scrap Instagram data, you can check first your web driver has worked properly. If everything is ok, it will drive automatically to Instagram’s page.</p><pre>browser.get(&quot;https://www.instagram.com/&quot;)</pre><p>I prefer to login session to scrap this data because Instagram has data restriction to getting more comment data without login.</p><p>Thanks again for Selenium that allows us to customize how browser start. Here, I will use WebDriverWait that lets us wait for elements to appear on the page — super useful on slow or dynamic websites (like Instagram). While waiting, I will set some condition using expected_condition.This gives us a set of <strong>conditions</strong> we can wait for — like waiting for an element to be <strong>present</strong>, <strong>clickable</strong>, <strong>visible</strong>, etc. For this time, we will customize until Instagram username and password appear and then, we fill the username and the password in the field.</p><pre>from selenium.webdriver.support.ui import WebDriverWait<br>from selenium.webdriver.support import expected_conditions as EC<br><br>username_field = WebDriverWait(driver, 10).until(<br>        EC.presence_of_element_located((By.NAME, &quot;username&quot;))<br>    )<br>username_field.send_keys(&quot;makelifeeasier&quot;) #input your username<br>    <br>password_field = driver.find_element(By.NAME, &quot;password&quot;)<br>password_field.send_keys(&quot;h4ppyM3&quot;) #input your password<br></pre><p><em>Where is login button?</em> Next element we should find is this login button.</p><pre>login_button = driver.find_element(By.XPATH, &quot;//button[@type=&#39;submit&#39;]&quot;)<br>login_button.click()</pre><p>We successfully logged in!</p><p>You know, Instagram sometimes asks us wanting to save our credentials or not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*o0IEGDvMroksqKyPw9iwAg.png" /></figure><p>We may add this adjustment to handle this.</p><pre>try:<br>        not_now_buttons = WebDriverWait(driver, 10).until(<br>            EC.presence_of_all_elements_located((By.XPATH, &quot;//div[contains(text(), &#39;Not Now&#39;)]&quot;))<br>        )<br>        for button in not_now_buttons:<br>            try:<br>                button.click()<br>                time.sleep(1)<br>            except:<br>                pass<br>    except:<br>        pass</pre><p>Ok, now you’re fully logged in — congrats! 🎉</p><p>From here, we’ll explore the data in the next part. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42f5edd7dca2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>