I am writing an extension, I was able to implement the parsing of the information I need from the page.

var xhr = new XMLHttpRequest(); xhr.open("GET", "http://steamcommunity.com/market/listings/730/AK-47%20%7C%20Redline%20%28Field-Tested%29", true); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { var data = xhr.responseText; var example = document.getElementById('example'); example.innerHTML = data; var name = document.getElementsByClassName("market_listing_item_name")[0].innerHTML; var priceO = document.getElementsByClassName("market_listing_price market_listing_price_with_fee")[0].innerHTML; dannie.innerHTML = priceO; dannie.innerHTML = name + " : " + priceO; // добавляется в блок с id=dannie цена } } xhr.send(); 

Parsing price from the trading floor. But how to implement, to parse several at once, 10-15 pieces of guns and the price would be constantly updated (for example, every 30 seconds).

For example, add a couple more guns 1. Another gun 2. Here is another

    1 answer 1

    In general, the approach to solving such a plan of a task is called Short polling , in other words, you simply make a request in n seconds. This is what is called a solution in the forehead, in this case it is ineffective , especially if you use a large number of url, respectively, a large number of requests.

    If changes occur less than once every n seconds, you risk driving traffic back and forth, that is, the payload in this case is zero.

    However, sample how this can be implemented.

     'use strict'; const URLS = [ 'http://steamcommunity.com/market/listings/730/AK-47%20%7C%20Redline%20%28Field-Tested%29', 'http://steamcommunity.com/market/listings/730/AK-47%20%7C%20Frontside%20Misty%20%28Field-Tested%29', 'http://steamcommunity.com/market/listings/730/AWP%20%7C%20Redline%20%28Minimal%20Wear%29' ]; function doRequest(url) { return new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.addEventListener('load', (event) => { if (event.status == 200) { const data = event.responseText; resolve(data); } else { const error = new Error(event.statusText); error.code = event.status; reject(error); } }); xhr.addEventListener('error', (event) => { reject(new Error('Network Error')); }); xhr.send(); }); } function parseURLS(URLS, timeout = 30) { setTimeout(() => { Promise.all(URLS.map(doRequest)) .then((results) => { results.forEach((result) => { var example = document.getElementById('example'); example.innerHTML = result; var name = document.getElementsByClassName("market_listing_item_name")[0].innerHTML; var priceO = document.getElementsByClassName("market_listing_price market_listing_price_with_fee")[0].innerHTML; dannie.innerHTML = priceO; dannie.innerHTML = name + " : " + priceO; // добавляется в блок с id=dannie цена }); }); }, timeout); } parseURLS(URLS); 

    It is possible that in order to solve your problem, it will be useful to explore what features the Steam API provides.

    • In another way, to make the logic of working with requests to Steam on the side, say php, nodejs-client and already directly to him to contact. But not every n seconds, but whenever the server responds. There will be such a situation that in this case, you will receive a response only when the server "will be what to answer" or the maximum waiting time for a request that hangs on the server is exceeded. View long polling information . In general terms, approximately the way it looks. - nakhodkiin
    • got it Or use steamAPI. - ThreegunD
    • According to the Steam API, I can’t say anything substantively, I just assumed the answer, read the documentation. - nakhodkiin