What is a Static Proxy?
Tags: webdev, productivity, security, beginners
Published: 2023-03-20 07:41:48




![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r4q7h2dhi5jsxo1mcv0x.png)<span class="c14 c25">


 </span></h1><p class="c20"><span style="overflow: hidden; display: inline-block; margin: 0.00px 0.00px; border: 0.00px solid #000000; transform: rotate(0.00rad) translateZ(0px); -webkit-transform: rotate(0.00rad) translateZ(0px); width: 624.00px; height: 310.67px;"><img alt="" src="images/image1.png" style="width: 624.00px; height: 310.67px; margin-left: 0.00px; margin-top: 0.00px; transform: rotate(0.00rad) translateZ(0px); -webkit-transform: rotate(0.00rad) translateZ(0px);" title=""></span></p><p class="c15"><span class="c3 c17"></span></p><p class="c0"><span class="c2">You probably already know or have heard about residential proxies. In short, they are the top answer on </span><span class="c13"><a class="c12" href="https://oxylabs.io/blog/how-to-hide-ip-address">how to hide an IP address</a></span><span class="c3 c2">&nbsp;by covering it up with another residential (legitimate) IP. Even though residential proxies are very reliable and block-free, they&rsquo;re not as fast as datacenter proxies. But what if there&#39;s a solution that combines the two &ndash; legitimacy and speed?</span></p><p class="c0"><span class="c2">This is where static proxies, also known as [static residential proxies](https://oxy.yt/dpa1), come in. Static proxies are connected to a single IP home address that doesn&rsquo;t change. In this article, we&rsquo;ll go over what they are, how they work, and how they could benefit your use case. Let&rsquo;s jump right in.</span></p><h2 class="c5" id="h.g5pmb643dte3"><span class="c27 c14">What are static proxies?</span></h2><p class="c0"><span class="c2">Static proxies are datacenter IPs assigned via a contract with an internet service provider (ISP). And as the name &ldquo;static&rdquo; implies, it allows you to operate as a residential user with the same IP for as long as required. Additionally, a static IP proxy allows you to avoid </span><span class="c13"><a class="c12" href="https://oxylabs.io/blog/rotate-ip-address">IP address rotation</a></span><span class="c3 c2">, making their use significantly simpler.</span></p><p class="c0"><span class="c2">Unlike regular datacenter proxies, static proxy services are not created by using virtual machines. </span><span class="c4">These proxies (also known as </span><span class="c22"><a class="c12" href="https://oxy.yt/hpsL">sticky IP</a></span><span class="c4">&nbsp;addresses) will look like genuine consumers for most websites.</span><span class="c2">&nbsp;As most websites will only see an average consumer browsing their services, static proxies will be significantly less likely to be flagged as potential bots.</span></p><h3 class="c30" id="h.xq3yme5shkmf"><span class="c28">Static proxy benefits</span></h3><p class="c1"><span class="c3 c2">Let&rsquo;s go through the key benefits a proxy with static IP offers:</span></p><ul class="c24 lst-kix_5ssncwhu71qy-0 start"><li class="c8 li-bullet-0"><span class="c11">Fast &ndash;</span><span class="c3 c2">&nbsp;originating from datacenter proxies, static proxies are just as fast as their counterparts. Usually hosted on virtual servers, static proxy IPs boast excellent bandwidth and high-speed internet connections.</span></li><li class="c8 li-bullet-0"><span class="c11">High anonymity &ndash;</span><span class="c3 c2">&nbsp;being assigned by an ISP, static IP proxies offer high anonymity and legitimacy.</span></li><li class="c8 li-bullet-0"><span class="c11">Reliable &ndash;</span><span class="c3 c2">&nbsp;Oxylabs&rsquo; static IP proxies are as reliable as they come &ndash; not only being assigned by an ISP but also coming from a reliable and proven source.</span></li><li class="c8 li-bullet-0"><span class="c11">Guaranteed up to 99% uptime &ndash;</span><span class="c3 c2">&nbsp;with the power of datacenter proxies and residential proxies &ndash; static proxies have the power of both. </span></li><li class="c8 li-bullet-0"><span class="c11">Unlimited number of targets &ndash; </span><span class="c3 c2">static IP proxies have no limits or restrictions when deployed for scraping.</span></li></ul><p class="c0"><span class="c3 c2">Note that the benefits above usually don&rsquo;t apply to free static proxy lists due to various feature cuts. As a rule of thumb, costly features can hardly be offered for free. </span></p><p class="c0"><span class="c3 c2">As the name suggests, a static IP proxy retains the same address over multiple sessions. Remember that maintaining the same IP addresses can be both beneficial and detrimental. Whether a static IP proxy service should be used depends on your goals.</span></p><h2 class="c5" id="h.507ivnlw5ksy"><span class="c14 c27">What are static IP proxies used for?</span></h2><p class="c0"><span class="c3 c2">Static proxies (AKA static residential proxies, static IP proxies) can be used when IP rotation is not a viable option. A static proxy service is used whenever changing addresses could lead to blocks or bans.</span></p><p class="c0"><span class="c2">Sometimes a </span><span class="c13"><a class="c12" href="https://oxy.yt/ppdR">rotating IP</a></span><span class="c3 c2">&nbsp;can cause issues or get banned from sites. This usually happens when making a purchase on e-commerce sites, creating social media accounts, or managing business operations on classified sites. Static IP proxy service is best suited for working with websites that require logging in. A static IP ensures a continuous session and lets you avoid interruptions such as re-entering user credentials. Static proxies allow you to continue using target websites and reap all the benefits of staying anonymous at the same time.</span></p><p class="c0"><span class="c3 c2">Static proxies create a unique solution for businesses looking to protect their brand. Those who try to illegitimately profit from abusing a brand&rsquo;s image will often try to block those companies from accessing their content. Static proxies allow businesses to afford incredibly high speeds to scrape the internet for possible copyright infringements or other illegal activities related to their brand and, at the same time, to resemble genuine consumers.</span></p><p class="c6"><span class="c2 c3">But the most common reason to use static proxies is quite apparent. In the words of Oxylabs&rsquo; experts: </span></p><p class="c7"><span class="c2 c31">A static proxy allows you to operate as a residential proxy user with the same IP address for as long as required. Simply put, you get a performance of a datacenter proxy along with the online reliability of a residential proxy.</span></p><h2 class="c5" id="h.rr16bggjhgd5"><span class="c27 c14">Conclusions </span></h2><p class="c0"><span class="c2">If you search for reliable proxy servers, static proxies with high anonymity of residential proxies and the speed of datacenter proxies are the way to go. A static IP proxy will be a key player in any project that relies on maintaining the same address and retaining online anonymity. </span></p></body></html>![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/12afp2wkbensxpd9xnbj.png)<p class="c8"><span style="overflow: hidden; display: inline-block; margin: 0.00px 0.00px; border: 0.00px solid #000000; transform: rotate(0.00rad) translateZ(0px); -webkit-transform: rotate(0.00rad) translateZ(0px); width: 342.50px; height: 192.34px;"><img alt="" src="images/image2.png" style="width: 342.50px; height: 192.34px; margin-left: 0.00px; margin-top: 0.00px; transform: rotate(0.00rad) translateZ(0px); -webkit-transform: rotate(0.00rad) translateZ(0px);" title=""></span></p><p class="c8"><span class="c1">This returns one element from the page. For this particular element, all we need is text. Text can be easily extracted with this line of code:</span></p><p class="c8"><span class="c6">document</span><span class="c5">.</span><span class="c2">querySelector</span><span class="c5">(</span><span class="c3">&#39;#firstHeading&#39;</span><span class="c5">).</span><span class="c6">textContent</span></p><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c1">The text can now be returned using the return keyword. The next step is to surround this in the evaluate method. This will ensure that this querySelector can be run.</span></p><p class="c8"><span class="c9">await</span><span class="c6">&nbsp;page</span><span class="c5">.</span><span class="c2">evaluate</span><span class="c5">(()</span><span class="c6">&nbsp;</span><span class="c0">=&gt;</span><span class="c6">&nbsp;</span><span class="c5">{</span></p><p class="c8"><span class="c6">&nbsp; &nbsp; </span><span class="c9">return</span><span class="c6">&nbsp;document</span><span class="c5">.</span><span class="c2">querySelector</span><span class="c5">(</span><span class="c3">&quot;#firstHeading&quot;</span><span class="c5">).</span><span class="c6">textContent</span><span class="c5">;</span></p><p class="c8"><span class="c5">});</span></p><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c1">The result of the evaluate() function can be stored in a variable to complete the functionality. Finally, do not forget to close the browser. Here is the complete script:</span></p><p class="c8"><span class="c9">const</span><span class="c6">&nbsp;puppeteer </span><span class="c0">=</span><span class="c6">&nbsp;</span><span class="c2">require</span><span class="c5">(</span><span class="c3">&quot;puppeteer&quot;</span><span class="c5">);</span></p><p class="c8"><span class="c4">&nbsp;</span></p><p class="c8"><span class="c5">(</span><span class="c9">async</span><span class="c6">&nbsp;</span><span class="c5">()</span><span class="c6">&nbsp;</span><span class="c0">=&gt;</span><span class="c6">&nbsp;</span><span class="c5">{</span></p><p class="c8"><span class="c6">&nbsp; </span><span class="c9">const</span><span class="c6">&nbsp;browser </span><span class="c0">=</span><span class="c6">&nbsp;</span><span class="c9">await</span><span class="c6">&nbsp;puppeteer</span><span class="c5">.</span><span class="c2">launch</span><span class="c5">();</span></p><p class="c8"><span class="c6">&nbsp; </span><span class="c9">const</span><span class="c6">&nbsp;page </span><span class="c0">=</span><span class="c6">&nbsp;</span><span class="c9">await</span><span class="c6">&nbsp;browser</span><span class="c5">.</span><span class="c2">newPage</span><span class="c5">();</span></p><p class="c8"><span class="c6">&nbsp; </span><span class="c9">await</span><span class="c6">&nbsp;page</span><span class="c5">.</span><span class="c2">goto</span><span class="c5">(</span><span class="c3">&quot;https://en.wikipedia.org/wiki/Web_scraping&quot;</span><span class="c5">);</span></p><p class="c8"><span class="c4">&nbsp;</span></p><p class="c8"><span class="c6">&nbsp; title </span><span class="c0">=</span><span class="c6">&nbsp;</span><span class="c9">await</span><span class="c6">&nbsp;page</span><span class="c5">.</span><span class="c2">evaluate</span><span class="c5">(()</span><span class="c6">&nbsp;</span><span class="c0">=&gt;</span><span class="c6">&nbsp;</span><span class="c5">{</span></p><p class="c8"><span class="c6">&nbsp; &nbsp; </span><span class="c9">return</span><span class="c6">&nbsp;document</span><span class="c5">.</span><span class="c2">querySelector</span><span class="c5">(</span><span class="c3">&quot;#firstHeading&quot;</span><span class="c5">).</span><span class="c6">textContent</span><span class="c5">.</span><span class="c2">trim</span><span class="c5">();</span></p><p class="c8"><span class="c6">&nbsp; </span><span class="c5">});</span></p><p class="c8"><span class="c6">&nbsp; console</span><span class="c5">.</span><span class="c2">log</span><span class="c5">(</span><span class="c6">title</span><span class="c5">);</span></p><p class="c8"><span class="c6">&nbsp; </span><span class="c9">await</span><span class="c6">&nbsp;browser</span><span class="c5">.</span><span class="c2">close</span><span class="c5">();</span></p><p class="c8"><span class="c5">})();</span></p><p class="c8 c10"><span class="c1"></span></p><h2 class="c11" id="h.rwva4gnw1lul"><span class="c14 c15 c7">Scraping multiple elements</span></h2><p class="c8"><span class="c1">Extracting multiple elements would involve three steps:</span></p><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c1">1. Use of querySelectorAll to get all elements matching the selector:</span></p><p class="c8"><span class="c6">headings_elements </span><span class="c0">=</span><span class="c6">&nbsp;document</span><span class="c5">.</span><span class="c2">querySelectorAll</span><span class="c5">(</span><span class="c3">&quot;h2 .mw-headline&quot;</span><span class="c5">);</span></p><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c1">2. create an array, as heading_elements is of type NodeList.</span></p><p class="c8"><span class="c6">headings_array </span><span class="c0">=</span><span class="c6">&nbsp;Array</span><span class="c5">.</span><span class="c2">from</span><span class="c5">(</span><span class="c6">headings_elements</span><span class="c5">);</span></p><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c1">3. Call the map() function can be called to process each element in the array and return it.</span></p><p class="c8"><span class="c9">return</span><span class="c6">&nbsp;headings_array</span><span class="c5">.</span><span class="c2">map</span><span class="c5">(</span><span class="c6">heading </span><span class="c0">=&gt;</span><span class="c6">&nbsp;heading</span><span class="c5">.</span><span class="c6">textContent</span><span class="c5">);</span></p><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c1">This of course needs to be surrounded by page.evaluate() function. Putting everything together, this is the complete script. You can save this as wiki_toc.js:</span></p><p class="c8"><span class="c9">const</span><span class="c6">&nbsp;puppeteer </span><span class="c0">=</span><span class="c6">&nbsp;</span><span class="c2">require</span><span class="c5">(</span><span class="c3">&quot;puppeteer&quot;</span><span class="c5">);</span></p><p class="c8"><span class="c4">&nbsp;</span></p><p class="c8"><span class="c5">(</span><span class="c9">async</span><span class="c6">&nbsp;</span><span class="c5">()</span><span class="c6">&nbsp;</span><span class="c0">=&gt;</span><span class="c6">&nbsp;</span><span class="c5">{</span></p><p class="c8"><span class="c6">&nbsp; </span><span class="c9">const</span><span class="c6">&nbsp;browser </span><span class="c0">=</span><span class="c6">&nbsp;</span><span class="c9">await</span><span class="c6">&nbsp;puppeteer</span><span class="c5">.</span><span class="c2">launch</span><span class="c5">();</span></p><p class="c8"><span class="c6">&nbsp; </span><span class="c9">const</span><span class="c6">&nbsp;page </span><span class="c0">=</span><span class="c6">&nbsp;</span><span class="c9">await</span><span class="c6">&nbsp;browser</span><span class="c5">.</span><span class="c2">newPage</span><span class="c5">();</span></p><p class="c8"><span class="c6">&nbsp; </span><span class="c9">await</span><span class="c6">&nbsp;page</span><span class="c5">.</span><span class="c2">goto</span><span class="c5">(</span><span class="c3">&quot;https://en.wikipedia.org/wiki/Web_scraping&quot;</span><span class="c5">);</span></p><p class="c8"><span class="c4">&nbsp;</span></p><p class="c8"><span class="c6">&nbsp; headings </span><span class="c0">=</span><span class="c6">&nbsp;</span><span class="c9">await</span><span class="c6">&nbsp;page</span><span class="c5">.</span><span class="c2">evaluate</span><span class="c5">(()</span><span class="c6">&nbsp;</span><span class="c0">=&gt;</span><span class="c6">&nbsp;</span><span class="c5">{</span></p><p class="c8"><span class="c6">&nbsp; &nbsp; headings_elements </span><span class="c0">=</span><span class="c6">&nbsp;document</span><span class="c5">.</span><span class="c2">querySelectorAll</span><span class="c5">(</span><span class="c3">&quot;h2 .mw-headline&quot;</span><span class="c5">);</span></p><p class="c8"><span class="c6">&nbsp; &nbsp; headings_array </span><span class="c0">=</span><span class="c6">&nbsp;Array</span><span class="c5">.</span><span class="c2">from</span><span class="c5">(</span><span class="c6">headings_elements</span><span class="c5">);</span></p><p class="c8"><span class="c6">&nbsp; &nbsp; </span><span class="c9">return</span><span class="c6">&nbsp;headings_array</span><span class="c5">.</span><span class="c2">map</span><span class="c5">(</span><span class="c6">heading </span><span class="c0">=&gt;</span><span class="c6">&nbsp;heading</span><span class="c5">.</span><span class="c6">textContent</span><span class="c5">);</span></p><p class="c8"><span class="c6">&nbsp; </span><span class="c5">});</span></p><p class="c8"><span class="c6">&nbsp; console</span><span class="c5">.</span><span class="c2">log</span><span class="c5">(</span><span class="c6">headings</span><span class="c5">);</span></p><p class="c8"><span class="c6">&nbsp; </span><span class="c9">await</span><span class="c6">&nbsp;browser</span><span class="c5">.</span><span class="c2">close</span><span class="c5">();</span></p><p class="c8"><span class="c5">})();</span></p><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c1">This file can now be run from your terminal:</span></p><p class="c8"><span class="c6">node wiki_toc</span><span class="c5">.</span><span class="c6">js</span></p><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c19">Bonus tip</span><span class="c1">: Array.from() function can be supplied with a map function directly, without a separate call to map. Depending on the comfort level, the same code can thus be written as:</span></p><p class="c8"><span class="c6">headings </span><span class="c0">=</span><span class="c6">&nbsp;</span><span class="c9">await</span><span class="c6">&nbsp;page</span><span class="c5">.</span><span class="c2">evaluate</span><span class="c5">(()</span><span class="c6">&nbsp;</span><span class="c0">=&gt;</span><span class="c6">&nbsp;</span><span class="c5">{</span></p><p class="c8"><span class="c6">&nbsp; &nbsp; </span><span class="c9">return</span><span class="c6">&nbsp;Array</span><span class="c5">.</span><span class="c2">from</span><span class="c5">(</span><span class="c6">document</span><span class="c5">.</span><span class="c2">querySelectorAll</span><span class="c5">(</span><span class="c3">&quot;h2 .mw-headline&quot;</span><span class="c5">),</span></p><p class="c8"><span class="c6">&nbsp; &nbsp; &nbsp; heading </span><span class="c0">=&gt;</span><span class="c6">&nbsp;heading</span><span class="c5">.</span><span class="c6">innerText</span><span class="c5">.</span><span class="c2">trim</span><span class="c5">());</span></p><p class="c8"><span class="c6">&nbsp; </span><span class="c5">});</span></p><p class="c8 c10"><span class="c1"></span></p><h2 class="c11" id="h.r2dbswn4i0nm"><span class="c14 c15 c7">Scraping a hotel listing page</span></h2><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c1">This section will explain how a typical listing page can be scraped to get a JSON object with all the required information. The concepts presented in this section will be applicable for any listing, whether it is an online store, a directory, or a hotel listing. </span></p><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c7">The example that we will take is Airbnb. Apply some filters so that you reach a page similar to the one in the screenprint. In this particular example, we will be scraping this </span><span class="c7 c17"><a class="c16" href="https://www.airbnb.com/s/homes?refinement_paths%255B%255D%3D%252Fhomes%26amp;search_type%3Dsection_navigation%26amp;property_type_id%255B%255D%3D8&amp;sa=D&amp;source=editors&amp;ust=1679045817280405&amp;usg=AOvVaw1kiYKxoo3bdqx2E5D1mIw2">Airbnb page</a></span><span class="c1">&nbsp;that lists 20 hotels. To scrape all 20 hotels, the first step is to identify the selector for each hotel section.</span></p><p class="c8"><span class="c6">root </span><span class="c0">=</span><span class="c6">&nbsp;Array</span><span class="c5">.</span><span class="c2">from</span><span class="c5">(</span><span class="c6">document</span><span class="c5">.</span><span class="c2">querySelectorAll</span><span class="c5">(</span><span class="c3">&quot;#FMP-target [itemprop=&#39;itemListElement&#39;]&quot;</span><span class="c5">));</span></p><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c1">This returns a NodeList of length 20 and stores it in the variable root. Note that so far, text or any attribute has not been extracted. All we have is an array &nbsp;of elements. This will be done in the map() function.</span></p><p class="c8"><span class="c6">hotels </span><span class="c0">=</span><span class="c6">&nbsp;root</span><span class="c5">.</span><span class="c2">map</span><span class="c5">(</span><span class="c6">hotel </span><span class="c0">=&gt;</span><span class="c6">&nbsp;</span><span class="c5">({</span><span class="c4">&nbsp;</span></p><p class="c8"><span class="c12">// code here</span></p><p class="c8"><span class="c5">}));</span></p><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c1">The URL of the photo of the hotel can be extracted with a code like this:</span></p><p class="c8"><span class="c6">hotel</span><span class="c5">.</span><span class="c2">querySelector</span><span class="c5">(</span><span class="c3">&quot;img&quot;</span><span class="c5">).</span><span class="c2">getAttribute</span><span class="c5">(</span><span class="c3">&quot;src&quot;</span><span class="c5">)</span></p><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c1">Getting the name of the hotel is a little trickier. The classes used on this page are some random words like _krjbj and _mvzr1f2. These class names appear to be generated dynamically and may change later on. It is better to have selectors which do not rely on these class names. </span></p><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c1">The hotel name can be extracted by combining parentElement and nextElementSibling selectors:</span></p><p class="c8"><span class="c6">hotel</span><span class="c5">.</span><span class="c2">querySelector</span><span class="c5">(</span><span class="c3">&#39;ol&#39;</span><span class="c5">).</span><span class="c6">parentElement</span><span class="c5">.</span><span class="c6">nextElementSibling</span><span class="c5">.</span><span class="c6">textContent</span></p><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c1">The most important concept to understand here is that we are concatenating querySelectors. Effectively, the first hotel name is being extracted with this line of code:</span></p><p class="c8"><span class="c6">document</span><span class="c5">.</span><span class="c2">querySelectorAll</span><span class="c5">(</span><span class="c3">&quot;#FMP-target [itemprop=&#39;itemListElement&#39;]&quot;</span><span class="c5">)[</span><span class="c13">0</span><span class="c5">].</span><span class="c2">querySelector</span><span class="c5">(</span><span class="c3">&#39;ol&#39;</span><span class="c5">).</span><span class="c6">parentElement</span><span class="c5">.</span><span class="c6">nextElementSibling</span><span class="c5">.</span><span class="c6">textContent </span></p><p class="c8"><span style="overflow: hidden; display: inline-block; margin: 0.00px 0.00px; border: 0.00px solid #000000; transform: rotate(0.00rad) translateZ(0px); -webkit-transform: rotate(0.00rad) translateZ(0px); width: 624.00px; height: 350.67px;"><img alt="" src="images/image1.png" style="width: 624.00px; height: 350.67px; margin-left: 0.00px; margin-top: 0.00px; transform: rotate(0.00rad) translateZ(0px); -webkit-transform: rotate(0.00rad) translateZ(0px);" title=""></span></p>
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ygdemr7eqpduog2tcibx.png)<p class="c8"><span class="c1">Finally, we can create an object containing both of these values. The syntax to create an object is like this:</span></p><p class="c8"><span class="c6">Hotel </span><span class="c0">=</span><span class="c6">&nbsp;</span><span class="c5">{</span></p><p class="c8"><span class="c6">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="c13">Name</span><span class="c0">:</span><span class="c6">&nbsp;</span><span class="c3">&#39;x&#39;</span><span class="c5">,</span></p><p class="c8"><span class="c6">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="c13">Photo</span><span class="c0">:</span><span class="c6">&nbsp;</span><span class="c3">&#39;y&#39;</span></p><p class="c8"><span class="c6">&nbsp; &nbsp; &nbsp; </span><span class="c5">}</span></p><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c1">Putting everything together, here is the final script. Save it as bnb.js.</span></p><p class="c8"><span class="c9">const</span><span class="c6">&nbsp;puppeteer </span><span class="c0">=</span><span class="c6">&nbsp;</span><span class="c2">require</span><span class="c5">(</span><span class="c3">&quot;puppeteer&quot;</span><span class="c5">);</span></p><p class="c8"><span class="c5">(</span><span class="c9">async</span><span class="c6">&nbsp;</span><span class="c5">()</span><span class="c6">&nbsp;</span><span class="c0">=&gt;</span><span class="c6">&nbsp;</span><span class="c5">{</span></p><p class="c8"><span class="c6">&nbsp; </span><span class="c9">let</span><span class="c6">&nbsp;url </span><span class="c0">=</span><span class="c6">&nbsp;</span><span class="c3">&quot;https://www.airbnb.com/s/homes?refinement_paths%5B%5D=%2Fhomes&amp;search_type=section_navigation&amp;property_type_id%5B%5D=8&quot;</span><span class="c5">;</span></p><p class="c8"><span class="c6">&nbsp; </span><span class="c9">const</span><span class="c6">&nbsp;browser </span><span class="c0">=</span><span class="c6">&nbsp;</span><span class="c9">await</span><span class="c6">&nbsp;puppeteer</span><span class="c5">.</span><span class="c2">launch</span><span class="c5">(</span><span class="c6">url</span><span class="c5">);</span></p><p class="c8"><span class="c6">&nbsp; </span><span class="c9">const</span><span class="c6">&nbsp;page </span><span class="c0">=</span><span class="c6">&nbsp;</span><span class="c9">await</span><span class="c6">&nbsp;browser</span><span class="c5">.</span><span class="c2">newPage</span><span class="c5">();</span></p><p class="c8"><span class="c6">&nbsp; </span><span class="c9">await</span><span class="c6">&nbsp;page</span><span class="c5">.</span><span class="c2">goto</span><span class="c5">(</span><span class="c6">url</span><span class="c5">);</span></p><p class="c8"><span class="c6">&nbsp; data </span><span class="c0">=</span><span class="c6">&nbsp;</span><span class="c9">await</span><span class="c6">&nbsp;page</span><span class="c5">.</span><span class="c2">evaluate</span><span class="c5">(()</span><span class="c6">&nbsp;</span><span class="c0">=&gt;</span><span class="c6">&nbsp;</span><span class="c5">{</span></p><p class="c8"><span class="c6">&nbsp; &nbsp; root </span><span class="c0">=</span><span class="c6">&nbsp;Array</span><span class="c5">.</span><span class="c2">from</span><span class="c5">(</span><span class="c6">document</span><span class="c5">.</span><span class="c2">querySelectorAll</span><span class="c5">(</span><span class="c3">&quot;#FMP-target [itemprop=&#39;itemListElement&#39;]&quot;</span><span class="c5">));</span></p><p class="c8"><span class="c6">&nbsp; &nbsp; hotels </span><span class="c0">=</span><span class="c6">&nbsp;root</span><span class="c5">.</span><span class="c2">map</span><span class="c5">(</span><span class="c6">hotel </span><span class="c0">=&gt;</span><span class="c6">&nbsp;</span><span class="c5">({</span></p><p class="c8"><span class="c6">&nbsp; &nbsp; &nbsp; </span><span class="c13">Name</span><span class="c0">:</span><span class="c6">&nbsp;hotel</span><span class="c5">.</span><span class="c2">querySelector</span><span class="c5">(</span><span class="c3">&#39;ol&#39;</span><span class="c5">).</span><span class="c6">parentElement</span><span class="c5">.</span><span class="c6">nextElementSibling</span><span class="c5">.</span><span class="c6">textContent</span><span class="c5">,</span></p><p class="c8"><span class="c6">&nbsp; &nbsp; &nbsp; </span><span class="c13">Photo</span><span class="c0">:</span><span class="c6">&nbsp;hotel</span><span class="c5">.</span><span class="c2">querySelector</span><span class="c5">(</span><span class="c3">&quot;img&quot;</span><span class="c5">).</span><span class="c2">getAttribute</span><span class="c5">(</span><span class="c3">&quot;src&quot;</span><span class="c5">)</span></p><p class="c8"><span class="c6">&nbsp; &nbsp; </span><span class="c5">}));</span></p><p class="c8"><span class="c6">&nbsp; &nbsp; </span><span class="c9">return</span><span class="c6">&nbsp;hotels</span><span class="c5">;</span></p><p class="c8"><span class="c6">&nbsp; </span><span class="c5">});</span></p><p class="c8"><span class="c6">&nbsp; console</span><span class="c5">.</span><span class="c2">log</span><span class="c5">(</span><span class="c6">data</span><span class="c5">);</span></p><p class="c8"><span class="c6">&nbsp; </span><span class="c9">await</span><span class="c6">&nbsp;browser</span><span class="c5">.</span><span class="c2">close</span><span class="c5">();</span></p><p class="c8"><span class="c5">})();</span></p><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c1">Run this file from the terminal using:</span></p><p class="c8"><span class="c6">node bnb</span><span class="c5">.</span><span class="c6">js</span></p><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c1">You should be able to see a JSON object printed on the console.</span></p><p class="c8 c10"><span class="c1"></span></p><h2 class="c11" id="h.iiriinsuuc5k"><span class="c14 c15 c7">Summary</span></h2><p class="c8 c10"><span class="c1"></span></p><p class="c8"><span class="c7">In this Puppeteer tutorial, various examples of web scraping have been explained. The examples ranged from extracting one element from a website and moving on to extracting hotel listings from a popular website. We recommend that you look at the official </span><span class="c17 c7"><a class="c16" href="https://pptr.dev/&amp;sa=D&amp;source=editors&amp;ust=1679045817294784&amp;usg=AOvVaw1s2TyjAprI-_cDyGv8njVr">Puppeteer documentation</a></span><span class="c7">&nbsp;for more detailed information.</span></p></body></html>