Home python How to rescue the site dns-shop.ru?

How to rescue the site dns-shop.ru?

Author

Date

Category

tried to do this:

Def Parser (Search):
  Headers = {'X-Requested-with': 'xmlhttprequest',
        'User-Agent': 'Mozilla / 5.0 (Windows NT 6.1; Wow64) AppleWebKit / 537.36 (KHTML, LIKE GECKO) Chrome / 77.0.3865.120 Yabrowser / 19.10.3.281 yowser / 2.5 Safari / 537.36'}
  url = 'https://www.dns-shop.ru/search/?q=' + search + '& amp; p = 1'
  Sesia = Requests.session ()
  Request = sesia.get (URL, Headers = Headers, Timeout = 5)
  Soup = BS (Request.Content, 'HTML.PARSER')
  Products = Soup.find_all ('Div', {'Class': 'Catalog-Item'})

tried through Selenium:

Def Parser (Search):
  url = 'https://www.dns-shop.ru/search/?q=' + search + '& amp; p = 1'
  Driver = WebDriver.chrome (chromedrivermanager (). Install ())
  DRIVER.GET (URL)
  CONTENT = driver.page_source.
  PRINT (CONTENT)

In response, I get everything except the goods as I understood works JSON. Please tell me how to spar it product.
Displays this script + footer

& lt; script type = "text / javascript" & gt;
  (Function (I, S, O, G, R, A, M) {i ['googleAnalyticsObject'] = R; I [R] = I [R] || FUNCTION () {
      (I [R] .Q = i [R] .Q || []). Push (Arguments)}, I [R] .l = 1 * New Date (); A = S.CreateElement (O),
    m = s.getelementsBytagname (O) [0]; A.async = 1; A.Src = g; m.parentnode.insertBefore (A, M)
  }) (Window, Document, 'script', 'https: //www.google-nalytics.com/analytics.js'j'ga');
  GA ('CREATE', 'UA-8349380-2', 'AUTO');
  GA ('REQUIRE', 'DISPLAYFEATURES');
  GA ('Require', 'Linkid');
  Ga ('Require', 'EC');
  ga ('set', 'dimension1', 'moscow');
  if (undefined! == window.commerce_param_buy) {
    GA ('SET', 'Dimension2', window.commerce_param_buy);
  }
  Ga ('send', 'pageview');
& lt; / script & gt;
& lt; script type = "text / javascript" & gt;
  / ** @Type {yandexdataalyer} * /
  Window.dataLayer = Window.dataLayer || [];
    Try {
    var yaparams = {"city": "MOSCOW"};
    (Function (M, E, T, R, I, K, A) {
      m [i] = m [i] || Function () {
        (m [i] .a = m [i] .a || []). Push (arguments);
      };
      m [i] .l = 1 * new date ();
      If (undefined! == M.commerce_param_buy) {
        yaparams.buy = m.commerce_param_buy;
      }
      k = e.createelement (t), a = e.getelementsbytagname (t) [0], k.async = 1, k.src = r, a.parentnode.insertBefore (k, a)})
    (Window, Document, "Script", "https://mc.yandex.ru/metrika/tag.js", "ym");
    ym (7967056, "init", {
      Clickmap: True,
      TrackLinks: True,
      AccurateTrackBounce: True,
      Webvisor: True,
      TrackHash: True,
      Ecommerce: "DataLayer",
      Params: yaparams
    });
    window.yacounterreachgoal = function (E, P) {ym (7967056, 'Reachgoal', E, P); }
  } Catch (E) {}
& lt; / script & gt;

Answer 1, Authority 100%

If you specify the query header x-Requested-with ':' xmlhttprequest ', then in response, it will come JSON , otherwise – honest HTML .

The first contains the search data itself, the second is the search data and a lot of things (Header, Footer, scripts, etc.).

Therefore, when receiving a response, you need to use the PARRER JSON , and then the PARRER HTML .

Example:

import json
from urllib.parse import urljoin
From BS4 Import Beautifulsoup
Import Requests.
DEF Get_Products (Search: Str) - & gt; List:
  Headers = {
    'X-Requested-with': 'xmlhttprequest',
    'User-Agent': 'Mozilla / 5.0 (Windows NT 10.0; Win64; x64; RV: 70.0) GECKO / 20100101 Firefox / 70.0'
  }
  URL = F'Https: //www.dns-shop.ru/search/? q = {search} & amp; p = 1 & amp; Order = Popular & amp; stock = all '
  Session = Requests.session ()
  session.headers.update (Headers)
  RS = session.get (URL)
  Data = JSON.Loads (RS.Text) 
Root = Beautifulsoup (Data ['HTML'], 'HTML.PARSER')
  Items = []
  For a in root.select ('. Product-Info__Title-Link & GT; A'):
    Items.append (
      (A.Get_Text (Strip = True), URLJOIN (RS.URL, A ['HREF'])))
    )
  Return Items.

Run:

if __name__ == '__main__':
  Name = 'Video Cards'
  Items = Get_Products (Name)
  Print (F'Search {Name! R} ... ')
  Print (F 'RESULT ({Len (Items)):')
  For Title, URL in Items:
    Print (F '{title! R}: {url}')
  Print ()

Result:

search 'video cards' ...
 Result (18):
  'MSI AMD Radeon RX 570 Armor OC [Rx 570 Armor 8G OC]': https://www.dns-shop.ru/product/2BEC09E3FC2E330/Videokarta-msi-MD-RADEON-RX-570-Armor-C RX-570-Armor-8G-OC /
  'MSI GeForce RTX 2060 Super Ventus OC [RTX 2060 Super Ventus OC]': https://www.dns-shop.ru/product/06580877a9c61b80/videokarta-msi-geforce-rtx-2060-super-ventus- ° RTX-2060-Super-Ventus-OC /
  'MSI GeForce RTX 2070 Super Gaming X TRIO video card [RTX 2070 Super Gaming X TRIO]': https://www.dns-shop.ru/product/893d7d1698bb3332/videokarta-msi-geforce-rtx-2070-super-gaming X-TRIO-RTX-2070-Super-Gaming-X-TRIO /
  'Video card Palit GeForce RTX 2060 Gaming Pro [NE62060018J9-1062A]': https://www.dns-shop.ru/product/89eb26e2156d1b80/videokarta-palit-geforce-rtx-2060-gaming-pro-ne62060018j9-1062a/
  'Sapphire AMD Radeon RX 590 Pulse video card [11289-06-20g]': https://www.dns-shop.ru/product/d4aa3e2690ab1b80/videokarta-sapphire-amd-radeon-rx-590-pulse-11289-06 -20g /
  'Cardboard Palit GeForce GTX 1660 Dual OC [NE51660S18J9-1161A]': https://www.dns-shop.ru/product/25db5664658c3332/videokarta-palit-geforce-gtx-1660-dual-oc-ne51660s18j9-1161a/
  'Gigabyte GeForce GTX 1660 OC [GV-N1660OC-6GD] video card': https://www.dns-shop.ru/product/38d7d1eb43d73332/videokarta-gigabyte-geforce-gigabyte-geforce-gtx-1660-oc-gv-n1660oc-6gd/
  'MSI AMD Radeon RX 570 Armor OC [RX 570 Armor OC]': https://www.dns-shop.ru/product/90db0b7a1f5f3330/videokarta-msi-amd-RADEON-RX-570-Armor-C RX-570-Armor-4G-OC /
  'Gigabyte AMD Radeon RX 5700 XT Gaming OC [GV-R57xtGaming OC-8GD]': https://www.dns-shop.ru/product/ec8f0a1dbfde1b80/videokarta-gigabyte-amd-gradeon-rx-5700-xt Gaming-OC-GV-R57XTGAMING-OC-8GD /
  'Gigabyte GeForce RTX 2060 Super Gaming OC [GV-N206Sgaming OC-8GC]': https://www.dns-shop.ru/product/bfa21bf998943332/videokarta-gigabyte-geforce-rtx-2060-super-gaming-oc -GV-N206SGAMING-OC-8GC /
  'MSI GeForce GTX 1660 Ventus XS 6G OCV1 Video Card [GTX 1660 Ventus XS 6G OCV1]': https://www.dns-shop.ru/product/1EF66ABCB1E3332/Videokarta-MSi-GeForce-GTX-1660-ventus-xS- 6G-OCV1-GTX-1660-Ventus-XS-6G-OCV1 /
  'MSI GeForce GTX 1660 Ventus XS OC [GTX 1660 Ventus XS 6G OC]': https://www.dns-shop.ru/product/849575aa4ac13332/videokarta-msi-geforce-gtx-1660-ventus-xs-oc -GTX-1660-Ventus-XS-6G-OC /
  'Video card KFA2 GeForce RTX 2070 Super Ex - 1 Click OC [27ISL6MDU9EK]': https://www.dns-shop.ru/product/ea111905a77a1b80/videokarta-kfa2-geforce-rtx-2070-supere-ex---1 -Click-OC-27ISL6MDU9EK /
  'MSI GeForce GTX 1660 Ti Gaming X [GTX 1660 TI Gaming X 6G]': https://www.dns-shop.ru/product/b3643ee130d03332/videokarta-msi-geforce-gtx-1660-ti-gaming-x -GTX-1660-Ti-Gaming-X-6G /
  'Sapphire AMD Radeon RX 570 Pulse video card [11266-66-20g]': https://www.dns-shop.ru/product/5a1c9bea39693332/videokarta-sapphire-amd-radeon-rx-570-pulse-11266-66 -20g /
  'MSI GeForce RTX 2060 Super Gaming X [RTX 2060 Super Gaming X]': https://www.dns-shop.ru/product/12eaefb3a9c71b80/videokarta-msi-geforce-rtx-2060-super-gaming-x RTX-2060-Super-Gaming-X /
  'MSI GeForce GTX 1660 Ti Armor OC [GTX 1660 Ti Armor 6G OC]': https://www.dns-shop.ru/product/c1bedbe329171b80/videokarta-msi-geforce-gtx-1660-ti-armor-oc -GTX-1660-Ti-Armor-6G-OC /
  'Sapphire AMD RADEON RX 590 Nitro + Special Edition OC video card [11289-01-20g]': https://www.dns-shop.ru/product/9013d2b9e6da1b80/videokarta-sapphire-md-radeon-rx-590-nitro- Special-Edition-OC-11289-01-20G /

PS.

Here it looks like PRINT (RS.TEXT) :


Answer 2, Authority 17%

We can work with ready-made prices (for example: https: // www.dns-shop.ru/files/price/price-Spb.zip ), in the room to be made thousands of requests to the site. Link for your city located in Footer Pages

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions