Spaces:
Runtime error
Runtime error
Commit ·
bfe7edf
1
Parent(s): 0078fd4
Update SephoraDirect.py
Browse files- SephoraDirect.py +4 -2
SephoraDirect.py
CHANGED
|
@@ -3,6 +3,9 @@ from bs4 import BeautifulSoup
|
|
| 3 |
import re
|
| 4 |
import csv
|
| 5 |
import psycopg2
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
class SephoraScraper:
|
| 8 |
def __init__(self):
|
|
@@ -24,7 +27,6 @@ class SephoraScraper:
|
|
| 24 |
burp0_headers = {"Sec-Ch-Ua": "\"Chromium\";v=\"117\", \"Not;A=Brand\";v=\"8\"", "X-Ufe-Request": "true", "Sec-Ch-Ua-Mobile": "?0", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.5938.132 Safari/537.36", "X-Dtpc": "5$505172501_268h23vBLLCMFBNGOLFAPFGHKUDBVTGKMEPJULD-0e0", "X-Dtreferer": "https://www.sephora.com/shop/makeup-cosmetics?currentPage=2", "Exclude_personalized_content": "true", "X-Requested-Source": "rwd", "Sec-Ch-Ua-Platform": "\"Windows\"", "Accept": "*/*", "Sec-Fetch-Site": "same-origin", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Dest": "empty", "Referer": "https://www.sephora.com/product/sephora-collection-total-coverage-blending-sponge-set-60-plant-based-P482303?skuId=2497220&icid2=products%20grid:p482303:product", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-US,en;q=0.9"}
|
| 25 |
try:
|
| 26 |
response = requests.get(burp0_url, headers=burp0_headers)
|
| 27 |
-
print(response.text)
|
| 28 |
return response.json()
|
| 29 |
except Exception as e:
|
| 30 |
print(e)
|
|
@@ -105,7 +107,7 @@ class SephoraScraper:
|
|
| 105 |
password="SFBtp4xnPeA2"
|
| 106 |
)
|
| 107 |
cur = conn.cursor()
|
| 108 |
-
cur.execute("INSERT INTO
|
| 109 |
conn.commit()
|
| 110 |
cur.close()
|
| 111 |
conn.close()
|
|
|
|
| 3 |
import re
|
| 4 |
import csv
|
| 5 |
import psycopg2
|
| 6 |
+
import datetime
|
| 7 |
+
import time
|
| 8 |
+
|
| 9 |
|
| 10 |
class SephoraScraper:
|
| 11 |
def __init__(self):
|
|
|
|
| 27 |
burp0_headers = {"Sec-Ch-Ua": "\"Chromium\";v=\"117\", \"Not;A=Brand\";v=\"8\"", "X-Ufe-Request": "true", "Sec-Ch-Ua-Mobile": "?0", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.5938.132 Safari/537.36", "X-Dtpc": "5$505172501_268h23vBLLCMFBNGOLFAPFGHKUDBVTGKMEPJULD-0e0", "X-Dtreferer": "https://www.sephora.com/shop/makeup-cosmetics?currentPage=2", "Exclude_personalized_content": "true", "X-Requested-Source": "rwd", "Sec-Ch-Ua-Platform": "\"Windows\"", "Accept": "*/*", "Sec-Fetch-Site": "same-origin", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Dest": "empty", "Referer": "https://www.sephora.com/product/sephora-collection-total-coverage-blending-sponge-set-60-plant-based-P482303?skuId=2497220&icid2=products%20grid:p482303:product", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-US,en;q=0.9"}
|
| 28 |
try:
|
| 29 |
response = requests.get(burp0_url, headers=burp0_headers)
|
|
|
|
| 30 |
return response.json()
|
| 31 |
except Exception as e:
|
| 32 |
print(e)
|
|
|
|
| 107 |
password="SFBtp4xnPeA2"
|
| 108 |
)
|
| 109 |
cur = conn.cursor()
|
| 110 |
+
cur.execute("INSERT INTO scraper_product (title, product_id, ingredients, url, store_name, date_created) VALUES (%s, %s, %s, %s, %s, %s)", (product['title'], product['product_id'], product['ingredients'], product['url'], product['store_name'], datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
|
| 111 |
conn.commit()
|
| 112 |
cur.close()
|
| 113 |
conn.close()
|