Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from requests import get
- from requests import Session
- from json import loads
- SEARCH_HEAD={
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- 'DNT': '1',
- 'Referer': 'https://www.ozon.ru/category/vibratory-9054/',
- 'sec-ch-ua': '"Chromium";v="94", "Google Chrome";v="94", ";Not A Brand";v="99"',
- 'sec-ch-ua-mobile': '?0',
- 'sec-ch-ua-platform': '"Windows"',
- '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',
- }
- from seleniumwire import webdriver
- from selenium.webdriver.chrome.options import Options
- import pickle
- import time
- chrome_options = Options()
- options = {
- 'proxy': {
- 'no_proxy': 'localhost,127.0.0.1'
- }
- }
- d = webdriver.Chrome(executable_path=r'C:\Users\biklu\chromedriver.exe',seleniumwire_options=options, options=chrome_options)
- d.get('https://www.ozon.ru/category/bluzy-i-rubashki-zhenskie-7511/')
- time.sleep(2)
- pickle.dump(d.get_cookies(), open("cookies2.pkl", "wb"))
- d.quit()
- print("Close browser")
- 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"
- def get(URL):
- cookies = pickle.load(open("cookies2.pkl", 'rb'))
- session = Session()
- for cookie in cookies:
- session.cookies.set(cookie['name'], cookie['value'])
- res = session.get(URL, headers=SEARCH_HEAD)
- f = open('a.json', 'w+', encoding='utf-8')
- f.write(res.text)
- f.close()
- f = open('a.json', 'r', encoding='utf-8')
- df = loads(f.read())
- f.close()
- counter_num = 0
- widgetStates = df['widgetStates']
- for el in widgetStates:
- items = loads(widgetStates[el])
- items = items['items']
- for el_item in items:
- print("\n")
- counter_num += 1
- print("LINK: ", el_item['action']['link'])
- print('isAdult:', el_item['isAdult'])
- mainStates = el_item['mainState']
- for mainState in mainStates:
- atom = mainState['atom']
- tp = atom['type']
- if tp == 'price':
- print('price:',atom['price']['price'])
- print('originalPrice:',atom['price']['originalPrice'])
- if tp == 'textAtom':
- print('textAtom:',atom['textAtom']['text'])
- if tp == 'textVariants':
- print('textVariants:',atom['textVariants']['items'])
- print('images:', el_item['tileImage']['images'])
- print('ВСЕГО ',counter_num)
- return 'https://www.ozon.ru/api/composer-api.bx/page/json/v2?url='+df['nextPage']
- # это в цикл
- URL = get(URL)
- print("next page", URL)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement