Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,538 changes: 8,538 additions & 0 deletions .ipynb_checkpoints/API_Project-checkpoint.ipynb

Large diffs are not rendered by default.

203 changes: 203 additions & 0 deletions .ipynb_checkpoints/Web_Scraper-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "6620b2a1-bbe4-465a-a82c-52f1501fcf50",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"from bs4 import BeautifulSoup\n",
"from selenium import webdriver\n",
"from selenium.webdriver.common.keys import Keys \n",
"from selenium.webdriver.common.action_chains import ActionChains\n",
"import smtplib\n",
"import time"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3f03f50f-7356-4d02-ad1b-6c613b68d5bc",
"metadata": {},
"outputs": [],
"source": [
"driver = webdriver.Chrome()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "fd8a8410-6a58-40fc-ab69-9f6b7c4265b0",
"metadata": {},
"outputs": [],
"source": [
"url='https://www.amazon.com.mx/gp/product/B01N4I8FOY/ref=ox_sc_act_image_11?smid=AVDBXBAVVSXLQ&th=1'"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "737395c4-fb73-4035-990c-ac244fba142c",
"metadata": {},
"outputs": [],
"source": [
"driver.get(url)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "e223e9cd-add8-4306-a1c5-fc7c44209a20",
"metadata": {},
"outputs": [],
"source": [
"headers = {\"User-Agent\":'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36' }"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "8ba7cb11-ddb1-443e-b363-94ae96de4c41",
"metadata": {},
"outputs": [],
"source": [
"page = requests.get(url, headers=headers)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "69673785-fada-4105-86f0-c7debe3c3339",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"200"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"page.status_code"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "25482058-6d5a-4dcf-9f4c-8af4e7d5736e",
"metadata": {},
"outputs": [],
"source": [
"def check_price():\n",
" page = requests.get(url, headers=headers)\n",
" soup = BeautifulSoup(page.content, 'html.parser')\n",
" title = soup.find(id ='productTitle').get_text()\n",
" price = soup.find('span',{'class':'a-price-whole'}).get_text()\n",
" product_title = (title.strip())\n",
" converted_price = (price.strip('.').replace(',' , '.'))\n",
" \n",
" if converted_price < 7000:\n",
" send_mail()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3cd9a59f-c02f-46ce-82eb-d44502c86e97",
"metadata": {},
"outputs": [],
"source": [
"def send_mail():\n",
" server = smtplib.SMTP('smtp.gmail.com',587)\n",
" server.ehlo()\n",
" server.starttls()\n",
" server.ehlo()\n",
" \n",
" server.login('jfconstantino1@gmail.com', 'ymkrpqttvgzyatoh')\n",
" \n",
" subject = 'Precio del producto deseado ha bajado aun mas >>> QUE BARATOO!! <<<'\n",
" body = 'Correle, revisa la liga del producto en Amazon https://www.amazon.com.mx/gp/product/B01N4I8FOY/ref=ox_sc_act_image_11?smid=AVDBXBAVVSXLQ&th=1 '\n",
" \n",
" msg = f'Subject:{subject}\\n\\n{body}'\n",
" \n",
" server.sendmail(\n",
" 'jfconstantino1@gmail.com',\n",
" 'jf_constantino@hotmail.com',\n",
" msg\n",
" )\n",
" \n",
" print('Un correo electronico se ha enviado') \n",
" \n",
"while(True):\n",
" time.sleep(1200)\n",
" send_mail()\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f698139e-b801-428f-8bb1-e03f4378d6b5",
"metadata": {},
"outputs": [],
"source": [
"send_mail()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "54d05605-c325-460a-b5b1-757977d738cb",
"metadata": {},
"outputs": [],
"source": [
"driver.quit()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "96405362-50f7-4e95-89ed-fb3a3fa3de36",
"metadata": {},
"outputs": [],
"source": [
"server.quit() "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bfc7dc14-1e58-4e68-a35e-bff14d65d692",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading