-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread.py
More file actions
33 lines (25 loc) · 755 Bytes
/
thread.py
File metadata and controls
33 lines (25 loc) · 755 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
'''this one is an example of scarp stock info from yahoo finance'''
from threading import Thread
import urllib
import re
symbolfile = open("symbols.txt",'r')
symbolslist = symbolfile.read().split('\n')
def th(ur):
base = 'https://ca.finance.yahoo.com/q?s='
url = base + ur
regex = '<span id="yfs_l84_'+ ur.lower() +'">(.+?)</span>'
pattern = re.compile(regex)
htmltext = urllib.urlopen(url).read()
results = re.findall(pattern, htmltext)
print ur, results
urls = ["http://www.businessinsider.com/",
"http://nytimes.com",
"http://www.yahoo.com",
"http://cnn.com"]
threadlist = []
for u in symbolslist:
t = Thread(target=th, args=(u,))
t.start()
threadlist.append(t)
for b in threadlist:
b.join()