Guest User

Untitled

a guest
Jul 10th, 2020
49
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import requests
  2. import re
  3. from bs4 import BeautifulSoup
  4. import pandas as pd
  5.  
  6.  
  7. def get_html(url):
  8.     r = requests.get(url)
  9.     return r.text
  10.  
  11.  
  12. def get_name_count(html):
  13.     result = pd.DataFrame(columns=['Название', 'Колличество'])
  14.  
  15.     names = []
  16.     counts = []
  17.  
  18.     soup = BeautifulSoup(html, 'lxml')
  19.  
  20.     items_name = soup.find_all('a', {'class': 'products__list-item-name'})
  21.     for item in items_name:
  22.         name = item.get_text().strip()
  23.         names.append(name)
  24.  
  25.     items_count = soup.find_all("div", class_="products__list-item-remains")
  26.     for item in items_count:
  27.         count = item.get_text().strip()
  28.         counts.append(count)
  29.     result['Название'] = names
  30.     result['Колличество'] = counts
  31.  
  32.     return names, counts
  33.  
  34.  
  35. url_list = [
  36.     'https://smokelab.me/catalog/tabak/adalya-50-g/', 'https://smokelab.me/catalog/tabak/afzal-40-g/',
  37.     'https://smokelab.me/catalog/tabak/alfakher-50-g/', 'https://smokelab.me/catalog/tabak/b3-50-g/',
  38.     'https://smokelab.me/catalog/tabak/black-burn-100-g/', 'https://smokelab.me/catalog/tabak/burn-100-g/?page=2'
  39.     'https://smokelab.me/catalog/tabak/black-burn-20-g/', 'https://smokelab.me/catalog/tabak/black-burn-200-g/',
  40.     'https://smokelab.me/catalog/tabak/bonche-80-g/', 'https://smokelab.me/catalog/tabak/burn-20-g/'
  41.     'https://smokelab.me/catalog/tabak/burn-200-g/','https://smokelab.me/catalog/tabak/burn-200-g/?page=2',
  42.     'https://smokelab.me/catalog/tabak/daily-hookah-200-g/','https://smokelab.me/catalog/tabak/daily-hookah-200-g/?page=2',
  43.     'https://smokelab.me/catalog/tabak/daily-hookah-40-g/','https://smokelab.me/catalog/tabak/daily-hookah-40-g/?page=2',
  44.     'https://smokelab.me/catalog/tabak/daly-code-20-g/','https://smokelab.me/catalog/tabak/darkside-100-g/',
  45.     'https://smokelab.me/catalog/tabak/darkside-100-g/?page=2','https://smokelab.me/catalog/tabak/darkside-100-g/?page=3',
  46.     'https://smokelab.me/catalog/tabak/darkside-100-g/?page=4','https://smokelab.me/catalog/tabak/darkside-100-g/?page=5',
  47.     'https://smokelab.me/catalog/tabak/darkside-250-g/','https://smokelab.me/catalog/tabak/darkside-250-g/?page=2',
  48.     'https://smokelab.me/catalog/tabak/darkside-250-g/?page=3','https://smokelab.me/catalog/tabak/darkside-250-g/?page=4',
  49.     'https://smokelab.me/catalog/tabak/darkside-250-g/?page=5','https://smokelab.me/catalog/tabak/darkside-core-(medium)-30-g/',
  50.     'https://smokelab.me/catalog/tabak/darkside-shot-30-g/','https://smokelab.me/catalog/tabak/do-you-tobacco-50-g/',
  51.     'https://smokelab.me/catalog/tabak/duft-100-g/','https://smokelab.me/catalog/tabak/duft-100-g/?page=2',
  52.     'https://smokelab.me/catalog/tabak/duft-all-in-25-g/','https://smokelab.me/catalog/tabak/element-100-g/',
  53.     'https://smokelab.me/catalog/tabak/element-100-g/?page=2','https://smokelab.me/catalog/tabak/element-100-g/?page=3',
  54.     'https://smokelab.me/catalog/tabak/element-200-g/','https://smokelab.me/catalog/tabak/element-200-g/?page=2',
  55.     'https://smokelab.me/catalog/tabak/element-200-g/?page=3','https://smokelab.me/catalog/tabak/element-40-g/',
  56.     'https://smokelab.me/catalog/tabak/element-40-g/?page=2','https://smokelab.me/catalog/tabak/element-40-g/?page=3',
  57.     'https://smokelab.me/catalog/tabak/element-40-g/?page=4','https://smokelab.me/catalog/tabak/frigate-20g/',
  58.     'https://smokelab.me/catalog/tabak/malaysian-tobacco-50-g/','https://smokelab.me/catalog/tabak/malaysian-tobacco-50-g/?page=2',
  59.     'https://smokelab.me/catalog/tabak/matt-pear-250-g/','https://smokelab.me/catalog/tabak/matt-pear-250-g/?page=2',
  60.     'https://smokelab.me/catalog/tabak/matt-pear-50-g/','https://smokelab.me/catalog/tabak/must-have-125-g/',
  61.     'https://smokelab.me/catalog/tabak/must-have-125-g/?page=2','https://smokelab.me/catalog/tabak/must-have-125-g/?page=3',
  62.     'https://smokelab.me/catalog/tabak/nash-40-g/','https://smokelab.me/catalog/tabak/satyr-100-g/',
  63.     'https://smokelab.me/catalog/tabak/satyr-100-g/?page=2','https://smokelab.me/catalog/tabak/satyr-100-g/?page=3',
  64.     'https://smokelab.me/catalog/tabak/satyr-100-g/?page=4','https://smokelab.me/catalog/tabak/satyr-25-g/',
  65.     'https://smokelab.me/catalog/tabak/satyr-25-g/?page=2','https://smokelab.me/catalog/tabak/sebero-100-g/',
  66.     'https://smokelab.me/catalog/tabak/sebero-100-g/?page=2','https://smokelab.me/catalog/tabak/sebero-20-g/',
  67.     'https://smokelab.me/catalog/tabak/sebero-20-g/?page=2','https://smokelab.me/catalog/tabak/sebero-200-g/',
  68.     'https://smokelab.me/catalog/tabak/sebero-200-g/?page=2','https://smokelab.me/catalog/tabak/sebero-40-g/',
  69.     'https://smokelab.me/catalog/tabak/sebero-40-g/?page=2','https://smokelab.me/catalog/tabak/sebero-le-75-g/',
  70.     'https://smokelab.me/catalog/tabak/smoke-angels-100-g/','https://smokelab.me/catalog/tabak/spectrum-100-g/',
  71.     'https://smokelab.me/catalog/tabak/spectrum-100-g/?page=2','https://smokelab.me/catalog/tabak/spectrum-100-g/?page=3',
  72.     'https://smokelab.me/catalog/tabak/spectrum-100-g/?page=4','https://smokelab.me/catalog/tabak/spectrum-250-g/',
  73.     'https://smokelab.me/catalog/tabak/spectrum-250-g/?page=2','https://smokelab.me/catalog/tabak/spectrum-250-g/?page=3',
  74.     'https://smokelab.me/catalog/tabak/tangiers-100-g/','https://smokelab.me/catalog/tabak/tangiers-100-g/?page=2',
  75.     'https://smokelab.me/catalog/tabak/tangiers-100-g/?page=3','https://smokelab.me/catalog/tabak/tangiers-100-g/?page=4',
  76.     'https://smokelab.me/catalog/tabak/tangiers-100-g/?page=5','https://smokelab.me/catalog/tabak/tangiers-250-g/',
  77.     'https://smokelab.me/catalog/tabak/tangiers-250-g/?page=2','https://smokelab.me/catalog/tabak/tangiers-250-g/?page=3',
  78.     'https://smokelab.me/catalog/tabak/tangiers-250-g/?page=4','https://smokelab.me/catalog/tabak/tangiers-250-g/?page=5',
  79.     'https://smokelab.me/catalog/tabak/world-tobacco-original-20-g/','https://smokelab.me/catalog/tabak/world-tobacco-original-20-g/?page=2',
  80.     'https://smokelab.me/catalog/tabak/world-tobacco-original-20-g/?page=3','https://smokelab.me/catalog/tabak/world-tobacco-original-200-g/',
  81.     'https://smokelab.me/catalog/tabak/x-tobacco-50-g/','https://smokelab.me/catalog/tabak/x-tobacco-50-g/?page=2',
  82.     'https://smokelab.me/catalog/tabak/zomo-50-g/','https://smokelab.me/catalog/tabak/sarma-100-g/',
  83.     'https://smokelab.me/catalog/tabak/severnyij-100-g/','https://smokelab.me/catalog/tabak/severnyij-100-g/?page=2',
  84.     'https://smokelab.me/catalog/tabak/severnyij-25-g/','https://smokelab.me/catalog/tabak/severnyij-25-g/?page=2',
  85. ]
  86. for url in url_list:
  87.     get_name_count(get_html(url))
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×