forked from midudev/curso-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_basic.py
More file actions
28 lines (19 loc) · 720 Bytes
/
01_basic.py
File metadata and controls
28 lines (19 loc) · 720 Bytes
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
# pip3 install requests -> instalas la dependencia para hacer peticiones
import requests
import re
url = 'https://www.apple.com/es/shop/buy-mac/macbook-air/'
response = requests.get(url)
if response.status_code == 200:
print('La petición fue exitosa')
html = response.text
print(html)
# regular expression para encontrar el precio
price_pattern = r'<span class="rc-prices-fullprice">(.*?)</span>'
match = re.search(price_pattern, html)
if match:
print(f"El precio del producto es: {match.group(1)}")
# get the title if the patter is found
title_pattern = r'<title>(.*?)</title>'
match = re.search(title_pattern, html)
if match:
print(f"El título de la web es: {match.group(1)}")