-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathapp.py
More file actions
36 lines (25 loc) · 837 Bytes
/
app.py
File metadata and controls
36 lines (25 loc) · 837 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
35
36
import urllib2
#import requests as req #windows py3
#import urllib.request #windows
from bs4 import BeautifulSoup
#1 getting web page:
web_page = 'https://finance.yahoo.com/quote/FB?p=FB'
#query the website and return the html to the variable page:
page = urllib2.urlopen(web_page)
#page = req.get(web_page)
#urllib.request.Request(web_page) #windows
#print(page)
soup = BeautifulSoup(page, 'html.parser')
#soup = BeautifulSoup(page.text, 'html.parser')
name_box = soup.find('h1', attrs={'class': 'D(ib)'})
# print(name_box)
name = name_box.text
print(name)
price_box = soup.find('span', attrs={'class': 'Fw(b)'})
price = price_box.text
print(price)
import csv
from datetime import datetime
with open('index.csv', 'a') as csv_file:
writer = csv.writer(csv_file)
writer.writerow([name, price, datetime.now()])