Advertisement
daniilak

Untitled

Oct 18th, 2021
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.88 KB | None | 0 0
  1. from requests import get
  2. from requests import Session
  3. from json import loads
  4. SEARCH_HEAD={
  5.     'Accept': 'application/json',
  6.     'Content-Type': 'application/json',
  7.     'DNT': '1',
  8.     'Referer': 'https://www.ozon.ru/category/vibratory-9054/',
  9.     'sec-ch-ua': '"Chromium";v="94", "Google Chrome";v="94", ";Not A Brand";v="99"',
  10.     'sec-ch-ua-mobile': '?0',
  11.     'sec-ch-ua-platform': '"Windows"',
  12.     'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36',
  13.  
  14. }
  15. from seleniumwire import webdriver
  16. from selenium.webdriver.chrome.options import Options
  17. import pickle
  18. import time
  19. chrome_options = Options()
  20. options = {
  21.     'proxy': {
  22.     'http': 'http://login:[email protected]:8000',
  23.     'https': 'https://login:[email protected]:8000',
  24.     'no_proxy': 'localhost,127.0.0.1'
  25.     }
  26. }
  27. d = webdriver.Chrome(executable_path=r'C:\Users\biklu\chromedriver.exe',seleniumwire_options=options, options=chrome_options)
  28. d.get('https://www.ozon.ru/category/bluzy-i-rubashki-zhenskie-7511/')
  29. time.sleep(2)
  30. pickle.dump(d.get_cookies(), open("cookies2.pkl", "wb"))
  31. d.quit()
  32. print("Close browser")
  33. URL = "https://www.ozon.ru/api/composer-api.bx/page/json/v2?url=/category/bluzy-i-rubashki-zhenskie-7511/?layout_container=categorySearchMegapagination&layout_page_index=2&page=2"
  34. def get(URL):
  35.     cookies = pickle.load(open("cookies2.pkl", 'rb'))
  36.     session = Session()
  37.     for cookie in cookies:
  38.         session.cookies.set(cookie['name'], cookie['value'])
  39.     res = session.get(URL, headers=SEARCH_HEAD)
  40.     f = open('a.json', 'w+', encoding='utf-8')
  41.     f.write(res.text)
  42.     f.close()
  43.     f = open('a.json', 'r', encoding='utf-8')
  44.     df = loads(f.read())
  45.     f.close()
  46.     counter_num = 0
  47.  
  48.     widgetStates = df['widgetStates']
  49.     for el in widgetStates:
  50.         items = loads(widgetStates[el])
  51.         items = items['items']
  52.         for el_item in items:
  53.             print("\n")
  54.             counter_num += 1
  55.             print("LINK: ", el_item['action']['link'])
  56.             print('isAdult:', el_item['isAdult'])
  57.             mainStates = el_item['mainState']
  58.             for mainState in mainStates:
  59.                 atom = mainState['atom']
  60.                 tp = atom['type']
  61.                 if tp == 'price':
  62.                     print('price:',atom['price']['price'])
  63.                     print('originalPrice:',atom['price']['originalPrice'])
  64.                 if tp == 'textAtom':
  65.                     print('textAtom:',atom['textAtom']['text'])
  66.                 if tp == 'textVariants':
  67.                     print('textVariants:',atom['textVariants']['items'])
  68.             print('images:', el_item['tileImage']['images'])
  69.  
  70.     print('ВСЕГО ',counter_num)
  71.     return 'https://www.ozon.ru/api/composer-api.bx/page/json/v2?url='+df['nextPage']
  72.  
  73. # это в цикл
  74. URL = get(URL)
  75. print("next page", URL)
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement