### Extract Links Using Each Loop Source: https://github.com/jdecampos/doc-bright-data/blob/main/10 - best-practices-for-web-scraper-ide.md This example demonstrates extracting link URLs using a traditional `each()` loop. While functional, array methods like `map()` are generally preferred for conciseness. ```javascript const links = []; $('.card.product-wrapper').each(function(i, el) { links.push({url: $(this).find('h4 a').attr('href')}); }) return links; ``` -------------------------------- ### Track Browser Event Listeners Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part3.md Starts tracking event listeners created by the browser. This is a prerequisite for later disabling them. ```javascript track_event_listeners(); ``` -------------------------------- ### Example Interaction Code for Web Scraper IDE Source: https://github.com/jdecampos/doc-bright-data/blob/main/05 - develop-a-self-managed-scraper-with-the-ide.md Use this JavaScript code to navigate a website, wait for specific elements, parse data, and collect it within the Web Scraper IDE. Ensure the target website structure matches the selectors used. ```javascript // Example interaction code navigate(input.url); wait('.product-list'); let data = parse(); collect(data); ``` -------------------------------- ### Capture and Replay GraphQL Requests Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part1.md The `capture_graphql()` function captures and replays GraphQL requests. It can be configured with options for payload and URL. Use `wait_captured()` to get captured requests and `replay()` to replay them with new variables. ```javascript let q = capture_graphql({ payload: {id: 'ProfileQuery'}, // you may need to pass url opt as RegExp in case when // graphql endpoint is not "*/graphql" which is default value // url: /\bgraphql\b/ // default }); navigate('https://example.com'); let [first_query, first_response] = q.wait_captured(); collect(first_response.data.profile); let second = q.replay({ variables: {other_id: 2}, }); collect(second.data.profile); ``` ```javascript let q = capture_graphql({ payload: {id: 'ProfileQuery'}, // you may need to pass url opt as RegExp in case when // graphql endpoint is not "*/graphql" which is default value // url: /\bgraphql\b/ // default }); navigate('https://example.com'); if (!q.is_captured()) click('#load_more'); let [first_query, first_response] = q.wait_captured(); collect(first_response.data.profile); let second = q.replay({ variables: {other_id: 2}, }); collect(second.data.profile); ``` -------------------------------- ### Example Parser Code for Web Scraper IDE Source: https://github.com/jdecampos/doc-bright-data/blob/main/05 - develop-a-self-managed-scraper-with-the-ide.md This JavaScript code parses HTML content to extract product details like title, price, and URL. It uses jQuery-like selectors to target elements within the '.product-list .item' class. The extracted URLs are converted to absolute URLs. ```javascript // Example parser code return { products: $('.product-list .item').map(function() { return { title: $(this).find('.title').text().trim(), price: $(this).find('.price').text().trim(), url: new URL($(this).find('a').attr('href'), location.href).href }; }).get() }; ``` -------------------------------- ### track_event_listeners Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part3.md Starts tracking event listeners created by the browser, which is necessary for later use of `disable_event_listeners()`. ```APIDOC ## track_event_listeners ### Description Starts tracking the event listeners that the browser creates. This function is a prerequisite for using `disable_event_listeners()` later. ### Syntax TRACK_EVENT_LISTENERS(); ### Examples ```javascript track_event_listeners(); ``` ``` -------------------------------- ### Get Browser Window Size Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part1.md The `browser_size()` function returns the current dimensions of the browser window. This is a placeholder function. ```javascript TBD ``` -------------------------------- ### Get Response Headers in JavaScript Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part2.md Retrieve the response headers from the last page load. Access specific headers like 'content-type' using object notation. ```javascript let headers = response_headers(); console.log('content-type', headers['content-type']); ``` -------------------------------- ### Navigate with Options Source: https://github.com/jdecampos/doc-bright-data/blob/main/04 - coding-environment-tutorials.md Customize navigation behavior using options like `wait_until`, `referer`, `timeout`, `header`, and `fingerprint`. ```javascript // waits until DOM content loaded event is fired in the browser navigate([url], {wait_until: 'domcontentloaded'}); ``` ```javascript // adds a referer to the navigation navigate([url], {referer: [url]}); ``` ```javascript // the number of milliseconds to wait for. Default is 30000 ms navigate([url], {timeout: 45000}); ``` ```javascript // add headers to the navigation navigate([url], {header : 'accept: text/html'}); ``` ```javascript // specify browser width/height navigate([url], {fingerprint: {screen: {width: 400, height: 400}}}); ``` -------------------------------- ### Get Redirect History Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part2.md Retrieves a list of URLs that the browser was redirected through since the last 'navigate' call. ```javascript navigate('http://google.com'); let redirects = redirect_history(); // returns: // [ // 'http://google.com', // 'http://www.google.com', // 'https://www.google.com/', // ] ``` -------------------------------- ### Process Product Listings Source: https://github.com/jdecampos/doc-bright-data/blob/main/02 - basic.md Navigates to individual product pages based on URLs extracted from search results. Use this to process each product found in a search. ```javascript navigate(input.search_page) let listings = parse().listings for (let listing_url of listings) next_stage({listing_url}) ``` -------------------------------- ### Navigate to URL with Options Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part2.md Navigates the browser to a specified URL. Supports options for waiting, referer, timeout, status code handling, and screen dimensions. ```javascript navigate(input.url); navigate('https://example.com'); ``` ```javascript navigate(`url`, {wait_until: 'domcontentloaded'}); ``` ```javascript navigate(`url`, {referer: `url`}); ``` ```javascript navigate(`url`, {timeout: 45000}); ``` ```javascript navigate(`url`, {allow_status: [404]}); ``` ```javascript navigate(`url`, { fingerprint: {screen: {width: 400, height: 400}}, }); ``` -------------------------------- ### Navigating to a URL in IDE Source: https://github.com/jdecampos/doc-bright-data/blob/main/04 - coding-environment-tutorials.md Use the `navigate` function to direct the browser session to a specified URL. It accepts a URL string or an object with navigation options. ```javascript navigate([url]); ``` ```javascript navigate(input.url); ``` ```javascript navigate('https://example.com'); ``` -------------------------------- ### Resolve URL in JavaScript Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part2.md Use this function to get the final URL after redirects. Ensure 'parse' and 'resolve_url' are available in the scope. ```javascript let {href} = parse().anchor_elem_data; collect({final_url: resolve_url(href)}); ``` -------------------------------- ### Collect Product Data Source: https://github.com/jdecampos/doc-bright-data/blob/main/02 - basic.md Navigates to a product page and collects the parsed product data. Use this after navigating to a specific product's page. ```javascript navigate(input.listing_url) collect(parse()) ``` -------------------------------- ### Get status code of last page load Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part3.md Retrieves the HTTP status code from the most recent page load operation. ```javascript collect({status_code: status_code()}); ``` -------------------------------- ### Get Element Bounding Box Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part1.md The `bounding_box()` function returns the coordinates of the first matched element relative to the page. It requires a CSS selector. ```javascript let box = bounding_box('.product-list'); // box == { // top: 10, // right: 800, // bottom: 210, // left: 200, // x: 200, // y: 10, // width: 600, // height: 200, // } ``` -------------------------------- ### Standard Navigation and Waiting Source: https://github.com/jdecampos/doc-bright-data/blob/main/10 - best-practices-for-web-scraper-ide.md For straightforward scraping tasks, use basic navigation and waiting functions. This approach is clear and avoids unnecessary complexity. ```javascript navigate("https://example.com"); wait('h1'); ``` -------------------------------- ### Moving to the Next Stage in IDE Source: https://github.com/jdecampos/doc-bright-data/blob/main/04 - coding-environment-tutorials.md The `next_stage` function initiates the next stage of the crawler, passing a specified input object. ```javascript next_stage({url: 'http://example.com', page: 1}); ``` -------------------------------- ### Get Text Content Safely Source: https://github.com/jdecampos/doc-bright-data/blob/main/10 - best-practices-for-web-scraper-ide.md Use `text_sane()` to safely extract text content, or apply string manipulation like `replace()` with regex to isolate numerical values. ```javascript let name = $('a').text_sane(); or if you need only numbers let value= +$('a').text().replace(/\D+/g, ''); ``` -------------------------------- ### load_html Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part2.md Loads an HTML string and returns a Cheerio instance, allowing for easy parsing and manipulation of the HTML content. ```APIDOC ## load_html ### Description Loads an HTML string and returns a Cheerio instance, allowing for easy parsing and manipulation of the HTML content. ### Parameters #### html - **html** (string) - Required - Any HTML string to be parsed. ``` -------------------------------- ### run_stage Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part3.md Executes a specific stage of the crawler using a new browser session, passing input data to it. ```APIDOC ## run_stage ### Description Executes a specific stage of the crawler using a new browser session, passing input data to it. ### Syntax ```javascript run_stage(, ); ``` ### Parameters - **stage** (number) - Required - The stage number to run (1 is the first stage). - **input** (object) - Required - An object containing input data to pass to the next browser session. ``` -------------------------------- ### next_stage Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part2.md Initiates the next stage of the crawler with a provided input object. This is used to pass data to subsequent crawling steps. ```APIDOC ## next_stage ### Description Initiates the next stage of the crawler with a provided input object. This is used to pass data to subsequent crawling steps. ### Parameters #### input - **input** (object) - Required - The input object to pass to the next browser session. ``` -------------------------------- ### Load HTML and Collect Data Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part2.md Loads an HTML string, parses it with Cheerio, and collects specific data. The 'load_html' function returns a Cheerio instance. ```javascript let $$ = load_html('

p1

p2

'); collect({data: $$('#p2').text()}); ``` -------------------------------- ### Collecting Money Data Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part4.md Instantiate a 'Money' object with a value and currency, then collect it. ```javascript let p = new Money(10, 'USD'); collect({product_price: p}); ``` -------------------------------- ### navigate Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part2.md Navigates the browser to a specified URL. It supports various options for controlling the navigation process, including waiting for specific events, setting referers, timeouts, and allowing specific HTTP status codes. ```APIDOC ## navigate ### Description Navigates the browser to a specified URL. It supports various options for controlling the navigation process, including waiting for specific events, setting referers, timeouts, and allowing specific HTTP status codes. ### Syntax navigate(, [opt]); ### Parameters #### url - **url** (string) - Required - The URL to navigate to. #### opt - **opt** (object) - Optional - Navigation options. - **wait_until** (string) - Optional - Specifies when to consider the navigation complete (e.g., 'domcontentloaded'). - **referer** (string) - Optional - Sets the referer header for the navigation. - **timeout** (number) - Optional - The time in milliseconds to wait for the navigation to complete. Defaults to 30000 ms. - **allow_status** (array) - Optional - An array of HTTP status codes that should not throw an error (e.g., [404]). - **fingerprint** (object) - Optional - Object to specify browser fingerprint properties like screen dimensions. - **screen** (object) - Optional - Screen properties. - **width** (number) - Optional - Screen width. - **height** (number) - Optional - Screen height. ``` -------------------------------- ### Running a Specific Stage in IDE Source: https://github.com/jdecampos/doc-bright-data/blob/main/04 - coding-environment-tutorials.md The `run_stage` function executes a specified stage of the crawler with a new browser session and input. ```javascript run_stage(2, {url: 'http://example.com', page: 1}); ``` -------------------------------- ### Emulate Device Viewport Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part4.md Changes the user agent and screen parameters to emulate a specific mobile device. This allows viewing pages as they would appear on different devices. ```javascript emulate_device('iPhone X'); emulate_device('Pixel 2'); ``` -------------------------------- ### Efficient Pagination with `rerun_stage()` Source: https://github.com/jdecampos/doc-bright-data/blob/main/10 - best-practices-for-web-scraper-ide.md For websites with pagination, call `rerun_stage()` from the root page for each page instead of from within each page. This enables parallel request processing and speeds up scraping. ```javascript navigate(input.url); let $ = html_load(html()); let next_page_url = $('.next_page').attr('href'); rerun_stage({url: next_page_url}); ``` ```javascript let url = new URL(input.url); if (input.page) url.searchParams.set('page', input.page); navegate(url); // The input.page does not exist except on the root page, from which we // have already invoked rerun_stage() for each page. if (input.page) return; let $ = html_load(html()); let total_products = +$('.total_pages').text(); let total_pages = Math.ceil(total_products / 20); total_pages = Math.min(total_pages, 50); for (let page=2;page<=total_pages;page++) rerun_stage({url: input.url, page}); ``` -------------------------------- ### Configure HTML Capture Options Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part2.md Sets options to control how HTML is captured, such as including coordinate attributes. ```javascript html_capture_options({ coordinate_attributes: true, }); ``` -------------------------------- ### request Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part2.md Make a direct HTTP request to a specified URL or with given options. Supports various HTTP methods and request configurations. ```APIDOC ## request ### Description Make a direct HTTP request. ### Parameters #### Path Parameters - **url | options** (string | object) - Required - The URL to make the request to, or an object containing request options. ### Request Body (if options object is used) #### Request Body - **url** (string) - Required - The URL for the request. - **method** (string) - Optional - The HTTP method (e.g., GET, POST). Defaults to GET. - **headers** (object) - Optional - An object containing request headers. - **body** (object) - Optional - An object representing the request body. ``` -------------------------------- ### Make HTTP Request in JavaScript Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part2.md Perform direct HTTP requests. Supports both simple URL strings and detailed options objects for methods, headers, and bodies. ```javascript let res = request('http://www.example.com'); ``` ```javascript let res = request({url: 'http://www.example.com', method: 'POST', headers: {'Content-type': 'application/json'}, body: {hello: 'world'}}) ``` -------------------------------- ### Interaction Code: Using Parsed Data for Requests Source: https://github.com/jdecampos/doc-bright-data/blob/main/11 - complete-web-scraper-ide-examples.md Illustrates how to extract data (like a product ID) from an HTML page during interaction, and then use that data to construct a dynamic request URL. ```javascript navigate("https://example.com/1"); tag_html("page1"); let page_html = html(); let page_html2 = wait_for_parser_value("page1"); // the same let $ = load_html(page_html); let req_id = $('.product-id').text(); tag_request("product_json", {url: "https://example.com/product/"+req_id}); ``` -------------------------------- ### Interaction Code: Tagging Multiple Pages Source: https://github.com/jdecampos/doc-bright-data/blob/main/11 - complete-web-scraper-ide-examples.md Demonstrates how to navigate through multiple pages and tag the HTML content of each page with a unique identifier for later parsing. ```javascript navigate("https://example.com/1"); tag_html("page1"); navigate("https://example.com/2"); tag_html("page2"); navigate("https://example.com/3"); tag_html("page3"); ``` -------------------------------- ### mouse_to Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part2.md Moves the mouse cursor to a specified (x, y) position on the page. This can be used to simulate user interaction. ```APIDOC ## mouse_to ### Description Moves the mouse cursor to a specified (x, y) position on the page. This can be used to simulate user interaction. ### Syntax mouse_to(, ); ### Parameters #### x - **x** (number) - Required - The target x-coordinate. #### y - **y** (number) - Required - The target y-coordinate. ``` -------------------------------- ### Collecting Image Data Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part4.md Instantiate an 'Image' object with a URL and collect it using the 'collect' function. ```javascript let i = new Image('https://example.com/image.png'); collect({image: i}); ``` -------------------------------- ### Basic Product Detail Page (PDP) Scraper Source: https://github.com/jdecampos/doc-bright-data/blob/main/11 - complete-web-scraper-ide-examples.md Scrapes detailed information from a product page, including company info, social links, and tech stack. Handles URL redirection and checks for 'Page not found'. ```javascript let url = new URL(input.url.replace('https://www.slintel.com','https://6sense.com')); url = new URL(url.pathname, 'https://6sense.com'); navigate(url); if (location.href === 'https://6sense.com/company') dead_page(`Page not found`); tag_html('html'); ``` ```javascript const $ = html_load(parser.html) const nextData = JSON.parse($('#__NEXT_DATA__').html()); const pageProps = nextData.props.pageProps; const companyInfo = pageProps.company_data.companyInfo; const linkedin = companyInfo.linkedin ? (companyInfo.linkedin.includes('http') ? companyInfo.linkedin : 'https://'+companyInfo.linkedin) : null; const techCategories = pageProps.company_data?.technologies_mapper_view?.categories ? Object.values(pageProps.company_data.technologies_mapper_view.categories).map(v => Object.keys(v)).flat() : null; const pageData = { "name": companyInfo.name, "about": companyInfo.company_description, "num_employees": companyInfo.employee_range, "type": companyInfo.company_type, "industries": companyInfo.industry_v2_ranked.filter(v=>v), "techstack_arr": techCategories, "country_code": companyInfo.country, "website": companyInfo.display_domain ? new URL(companyInfo.display_domain.includes('http') ? companyInfo.display_domain : 'https://'+companyInfo.display_domain) : null, "social_media_urls": linkedin, "company_news": pageProps.company_data.company_news.map(v=>({ title: "company_news_data", date: "", link: "", })), "last_updated": new Date(companyInfo.last_updated_at*1e3), "url": new URL(parser.html_url), "logo": companyInfo.logo, "location": companyInfo.location, "region": [companyInfo.country, companyInfo.state].filter(v=>v).join(', '), "id": nextData.query.companyid, "slintel_resources": companyInfo.recommended_companies.map(v=>({ link: v.display_domain ? new URL(v.display_domain.includes('http') ? v.display_domain : 'https://'+v.display_domain) : null, title: v.name, type: v.company_type, })), "stock_symbol": companyInfo.stock_symbol, }; return pageData; ``` -------------------------------- ### Accessing Input Data in IDE Source: https://github.com/jdecampos/doc-bright-data/blob/main/04 - coding-environment-tutorials.md The global `input` object provides access to trigger input or results from previous stages. ```javascript navigate(input.url); ``` -------------------------------- ### Clicking Elements in IDE Source: https://github.com/jdecampos/doc-bright-data/blob/main/04 - coding-environment-tutorials.md The `click` function simulates a mouse click on a specified element after it appears on the page. ```javascript click(); ``` ```javascript click('#show-more'); ``` -------------------------------- ### Using Cheerio for DOM Manipulation Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part4.md Utilize the '$' instance, which is a cheerio object, to select and manipulate elements in the HTML. ```javascript $('#example').text(); $('$example').attr('href'); $('#example').text_sane(); /* This is like $().text() but also trims text and replace all space characters with single space "a b \t\n\n c" -> "a b c" */ ``` -------------------------------- ### Parse User Activity Summary Source: https://github.com/jdecampos/doc-bright-data/blob/main/11 - complete-web-scraper-ide-examples.md Extracts various summary statistics for user activity, including reputation, posts, and badges. Includes error handling for JSON parsing. ```javascript 'topactivity': ($) => { let summary_graph_data; try { summary_graph_data = JSON.parse( /graphDatas[^[]+([[^]]+])/gm.exec( $('*').first().html())?.[1]); } catch(e) { console.log('graphData not found') } let [summary_people_reached, summary_posts_edited, summary_helpful_flags, summary_votes_cast] = $('div:not(.js-highlight-box-reputation) > h1.flex--item + div .flex--item .fs-body3') .toArray().map(v=>$(v).text_sane().replace(/,/gm, '') || null); return { summary_reputation: +$('#top-cards h4.fs-headline1') .text().replace(/D+/gm, ''), summary_top_overall: $('a[href*="alltime"]') .first().text_sane() || null, summary_next_tag_badge: $('#rep-card-next-tag-badge a') .text_sane() || null, summary_graph_data, summary_next_tag_score: $('div.fl-shrink1 + div.fl-grow1 .fs-fine') .first().text_sane().replace(/,/gm, '') || null, summary_next_tag_answers: $('div.fl-shrink1 + div.fl-grow1 .fs-fine') .last().text_sane().replace(/,/gm, '') || null, summary_badges: $('h3 +div .s-badge').toArray() .map(v => $(v).attr('title')).join(', '), summary_last_badge: $('#badge-card-last').text_sane() || null, summary_next_badge: { name: $('#js-badge-card-next').text_sane() || null, progress: $('h4.flex--item.ws-nowrap + span') .text_sane() || null }, summary_people_reached, summary_posts_edited, summary_helpful_flags, summary_votes_cast, }; }, ``` -------------------------------- ### tag_download Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part3.md Allows capturing files downloaded by the browser based on a URL pattern. ```APIDOC ## tag_download ### Description Allows capturing files downloaded by the browser based on a URL pattern. ### Syntax ```javascript tag_download(); ``` ### Parameters - **url** (RegExp|string) - Required - A pattern or string to match the download URL against. ### Usage Example ```javascript let SEC = 1000; let download = tag_download(/example.com\/foo\/bar/); click('button#download'); let file1 = download.next_file({timeout: 10*SEC}); let file2 = download.next_file({timeout: 20*SEC}); collect({file1, file2}); ``` ``` -------------------------------- ### Interaction Code: Navigate and Parse (Old vs. New) Source: https://github.com/jdecampos/doc-bright-data/blob/main/11 - complete-web-scraper-ide-examples.md Compares old and new syntax for navigating to a URL and parsing content in the Web Scraper IDE. The new syntax simplifies data collection. ```javascript // Old code navigate("https://example.com"); collect(parse()); // New code navigate("https://example.com"); // New code alternative navigate("https://example.com"); tag_html("html_key"); ``` -------------------------------- ### Using the URL Class in IDE Source: https://github.com/jdecampos/doc-bright-data/blob/main/04 - coding-environment-tutorials.md The `URL` class, part of NodeJS's standard 'url' module, can be instantiated to parse and manipulate URL strings. ```javascript let u = new URL('https://example.com'); ``` -------------------------------- ### Handle Dead Pages with 'dead_page' Condition Source: https://github.com/jdecampos/doc-bright-data/blob/main/10 - best-practices-for-web-scraper-ide.md When using the navigate command, add a 'dead_page' condition to check for non-existent pages. This prevents unnecessary retries, especially when the website returns status codes other than 404. ```javascript try { // no need to wait 30sec 'ok-selector' in case of dead_page() wait('ok-selector'); } catch(e) { // in this case we can't be sure that the page is real dead dead_page('Page doesn\'t exist'); } ``` ```javascript wait('ok-selector, 404-selector'); if (el_exists('404-selector')) dead_page(); ``` -------------------------------- ### Tag downloaded files Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part3.md Captures files downloaded by the browser based on a URL pattern. Allows for sequential retrieval of downloaded files with timeouts. ```javascript let SEC = 1000; let download = tag_download(/example.com\/foo\/bar/); click('button#download'); let file1 = download.next_file({timeout: 10*SEC}); let file2 = download.next_file({timeout: 20*SEC}); collect({file1, file2}); ``` -------------------------------- ### right_click Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part3.md Simulates a right-click on a specified element. It waits for the element to appear before performing the action. ```APIDOC ## right_click ### Description Simulates a right-click on a specified element. It waits for the element to appear before performing the action. ### Syntax ```javascript right_click(); ``` ### Parameters - **selector** (string) - Required - The CSS selector of the element to right-click on. ``` -------------------------------- ### Check Element Existence Before Proceeding Source: https://github.com/jdecampos/doc-bright-data/blob/main/10 - best-practices-for-web-scraper-ide.md Use `el_exists` to verify if an element is present on the page before attempting to interact with it. Throws an error if the element is not found, preventing further script execution on a malformed page. ```javascript if (!el_exists('.product-title')) throw new Error('Failed to load product page'); ``` -------------------------------- ### Hover on Element Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part2.md Waits for an element to appear and then hovers over it. Use a CSS selector to specify the element. ```javascript hover('#item'); ``` -------------------------------- ### Collecting Data Lines in IDE Source: https://github.com/jdecampos/doc-bright-data/blob/main/04 - coding-environment-tutorials.md Use the `collect` function to add a data line to the crawler's dataset. It can optionally include a validation function. ```javascript collect([data_line] [validate_fn]); ``` ```javascript collect({ title: page_data.title, price: page_data.price }); ``` ```javascript collect({ price: data.price }); ``` ```javascript collect(line, l=>!l && throw new Error('Empty line')); ``` -------------------------------- ### Loading More Content with Scroll in IDE Source: https://github.com/jdecampos/doc-bright-data/blob/main/04 - coding-environment-tutorials.md The `load_more` function simulates scrolling to the bottom of a list to trigger lazy-loaded content, commonly used on infinite-scroll sites. ```javascript load_more(); ``` ```javascript load_more('.search-results'); ``` -------------------------------- ### html_capture_options Source: https://github.com/jdecampos/doc-bright-data/blob/main/09 - functions-part2.md Configures options for how HTML content is captured during the crawling process. This allows for fine-tuning the data extraction. ```APIDOC ## html_capture_options ### Description Configures options for how HTML content is captured during the crawling process. This allows for fine-tuning the data extraction. ### Parameters #### options - **options** (object) - Required - An object which accepts options defining how HTML capturing should be processed. - **coordinate_attributes** (boolean) - Optional - If true, coordinate attributes will be captured. ``` -------------------------------- ### Selecting Options in Dropdowns in IDE Source: https://github.com/jdecampos/doc-bright-data/blob/main/04 - coding-environment-tutorials.md The `select` function is used to choose a specific value from a select (dropdown) element. ```javascript select(