-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKith.py
More file actions
55 lines (47 loc) · 1.92 KB
/
Kith.py
File metadata and controls
55 lines (47 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import requests
from bs4 import BeautifulSoup
import json
def keysearch(key):
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36'}
url = 'https://kith.com/sitemap_products_1.xml?from=135297231&to=2057600008261'
r = requests.get(url=url, headers=headers)
soup = BeautifulSoup(r.text, 'html.parser')
mylist = []
global mylists
mylists = mylist
for items in soup.find_all("url"):
item = items.find("image:title")
if item is not None:
title = item.text
url = items.find("loc").text
time = items.find("lastmod").text
if keyword.lower() in title.lower():
print(title, url)
mylist.append(title)
purl = ('{}.json'.format(url))
r2 = requests.get(url=purl, headers=headers)
data = json.loads(r2.content)
for proditems in data['product']['variants']:
variant = proditems['id']
size = proditems['title']
link = 'https://www.kith.com/cart/{}:1'.format(variant)
print(' ',size,'ATC:',link)
print()
else:
if keyword.lower() in url.lower():
mylist.append(url)
print('Keyword Not in Item Name, but Found {}'.format(url))
if item is None:
url2 = items.find("loc").text
if keyword.lower() in url2.lower():
mylist.append(url2)
print('Keyword Not in Item Name, but Found {}'.format(url2))
while True:
keyword = input('Enter Keyword, Hit Enter When Ready:').lower()
if keyword == "":
print('Program Ended')
break
keysearch(keyword)
if len(mylists) == 0:
print('No Results for {}'.format(keyword).title())
print()