-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathting.py
More file actions
executable file
·34 lines (26 loc) · 824 Bytes
/
Copy pathting.py
File metadata and controls
executable file
·34 lines (26 loc) · 824 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
29
30
31
32
33
34
#!/Users/juan/anaconda3/bin/python3
import requests
from bs4 import BeautifulSoup
from datetime import date
def extract_price(str):
digits = ''
for c in str:
if c.isdigit():
digits += c
return int(digits)
def run():
path = '/Users/juan/projects/precios-tinglesa'
f = open(path + '/result.csv', 'a')
d = date.today().isoformat()
products = open(path + '/products', 'r').readlines()
for url in products:
url = url.replace("\n","")
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
s = soup.find_all(id='TXTPRICE')[0]
price = extract_price(s.get_text())
product_id = url.split('?')[1]
f.write('{},{},{}\n'.format(d, product_id, price))
f.close()
if __name__ == '__main__':
run()