How to do a search by title in the html?

I need help, I want to make a bot in JS.

Here the blocks on the website

5c9ba2d1385db970273064.png

They consist of something like this is html code

<div class="featured-item app_1912_1 item_909558480 buyers-club-item-has sm wear scanned" data-amount="471" data-sku="218" id="cartItem909558480"><img class="loading loading-async" src="/images/opskins-loading.gif" alt="Loading" style="display: none;"><a class="glyphicon glyphicon-search market-name market-search-icon opskins-search-button" href="/?loc=shop_search&amp;app=1912_1&amp;search_item=%22Tec-9+%7C+Critical+II%22&amp;search_internal=1" title="Search"></a><a class="opskins-screenshot-button show-screenshots success" title="View item in the game!" href='javascript:showScreenshot(909558480, "Tec-9 | II Critical (Battle-Scarred)", 471, 0.96594566106796260, 160, null, 1912, {"thumb":"https:\/\/files.opskins.media\/file\/vgo-img\/previews\/7842604_thumb.jpg","image1":"https:\/\/files.opskins.media\/file\/vgo-img\/previews\/7842624_front.jpg","image2":"https:\/\/files.opskins.media\/file\/vgo-img\/previews\/7842624_back.jpg","video1":"https:\/\/files.opskins.media\/file\/vgo-img\/previews\/7842624_video.webm"}, "", "")'>< span class="glyphicon glyphicon-screenshot"></span></a> <a class="market-name market-link" style="" href="?loc=shop_view_item&amp;item=909558480">
Tec-9 | II Critical
</a><div class="item-desc"> <small class="text-muted">Battle-Scarred</small>
<small style="color:#8847ff;">Restricted Pistol</small>
<small class="item-warning"></small>
<div class="good-deal-discount-pct"><span class="label label-success">16% Off</span></div></div><div class="item-img-container"><a href='javascript:showScreenshot(7842624, "Tec-9 | II Critical (Battle-Scarred)", 471, 0.96594566106796260, 160, 1, 1912, {"thumb":"https:\/\/files.opskins.media\/file\/vgo-img\/previews\/7842604_thumb.jpg","image1":"https:\/\/files.opskins.media\/file\/vgo-img\/previews\/7842624_front.jpg","image2":"https:\/\/files.opskins.media\/file\/vgo-img\/previews\/7842624_back.jpg","video1":"https:\/\/files.opskins.media\/file\/vgo-img\/previews\/7842624_video.webm"}, "", "")'><img class="item-img img-responsive img-fallback media-async-complete" src="https://files.opskins.media/file/vgo-img/previews/7842604_thumb.jpg" data-mediasrc="https://files.opskins.media/file/vgo-img/previews/7842604_thumb.jpg" data-async-media="image" alt="Tec-9 | Critical II" data-fallback="https://files.opskins.media/file/vgo-img/item/tec-9-critical-ii-battle-scarred-600.png" style="display: inline;"></a></div><div class="item-detail-container"> <div class="home-container">
<div class="number" title="Unbox the Serial number for this item">
The number
<span class="box">270</span>
</div>
<div class="remaining">
<div class="unboxed" title="All objects of one type unboxed">
unpacked
<span class="box">681</span>
</div>
</div>
</div><span style="position: absolute;top:-35px;right:5px;opacity:.5;"><img style="width: 32px;"src="https://opskins.com/images/games/logo-small-vgo.jpg" title="VGO" data-appid="1912" alt="VGO"></span><div class="buyers-club-icon"><span class="fa fa-money green" title="Only Buyers Club for the next 3 Minutes"></span></div><div class="item-amount" onclick="showGraphFromId(909558480)">$4.71<span class="converted amount">~305,61&nbsp;RUB</span></div><div class="market-name" style="padding-bottom:0.3 em;"><i class="icon-logo" title="OPSkins 7-Day Average"></i> MSRP: <span class="suggested-price">$5.61</span></div><div class="item-buttons"><button data-buttontype="addtocart" class="btn btn-orange btn-add-to-cart" type="button" data-amount="471" data-appid="1912" data-contextid="1" data-classid="7842624" data-id="909558480" data-item_id="12761262" data-market_name="Tec-9% 20%7C%20Critical%20II%20%28Battle-Scarred%29" data-sale_status="2" data-type="Restricted Pistol" data-wear="0.96594566106796260" data-bundles="[]" onclick="addToCart(909558480, 1912, 471, this)"> To Cart</button><button class="btn btn-success" data-amount="471" data-appid="1912" data-classid="7842624" data-id="909558480" data-item_id="12761262" data-market_name="Tec-9 | II Critical (Battle-Scarred)"data-sale_status="2" data-type="Restricted Pistol" data-wear="0.96594566106796260" type="button" onclick="oneClickBuy(909558480, 1912, 471, this)" title="Buy this item directly, without using a basket."> Buy Now</button></div></div><div class="wear"><div class="wear-value"><small class="text-muted" title="the Degree of wear:0.96594566106796">Wear:96.59457%</small></div><div class="wear-pointer"><i class="glyphicon glyphicon-triangle-bottom" style="left:96.594566106796%;" title="the Degree of wear:0.96594566106796"></i></div><div class="progress"><div class="progress-bar progress-bar-fn" style="width: 7%;" title="factory"></div><div class="progress-bar progress-bar-success" style="width: 8%;"title="a Little worn"></div><div class="progress-bar progress-bar-warning" style="width: 23%;" title="field test"></div><div class="progress-bar progress-bar-danger" style="width: 7%;" title="Worn"></div><div class="progress-bar progress-bar-bs" style="width: 55%;" title="battle-hardened"></div></div></div></div>


I want to see if there is a discount of more than 15% then he presses purchase and adds the product to cart. I have already done to find a discount and found the id of an item. How to make it in text (Or your own version to tell) found id and clicked buy

Here is my code
var searchSale = function() {
 var sale = document.querySelectorAll('.label-success');
 var maxSales = 0;
 var minSales = 15; //setting minimum discounts
 for (var i = 0; i < sale.length; i++) {
 if (Number.parseInt(sale[i].innerHTML.substr(-10,2)) > minSales) {
 maxSales = sale[i].innerHTML;
};
};

 return maxSales;
};

var searchProductSale = searchSale();

var searchProduct = function() {
 var product = document.querySelectorAll('.featured-item');
 for (var i = 0; i < product.length; i++) {
console.log(product[i].innerHTML);
};
};

searchProduct();
March 19th 20 at 08:54
1 answer
March 19th 20 at 08:56
Solution
for (var i = 0; i < sale.length; i++) {
 if (Number.parseInt(sale[i].innerHTML.substr(-10,2)) > minSales) {
 maxSales = sale[i].innerHTML;
 // save this block
 divWithMaxSale = sale[i].closest('.featured-item')
};
 };


https://developer.mozilla.org/en-US/docs/Web/API/E...
something like that keep the entire unit with max discount, well, when you have a block, you can it through divWithMaxSale.querySelector('button to cart') button to find it .click()

it should work

upd
--

well, or you can iterate through all document.querySelectorAll('.featured-item'), and in each iteme to look for this .label-success , and later still that it was not necessary to seek parental controls via .closest()

Find more questions by tags JavaScript