-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathnist-attenuation-scraper.py
55 lines (46 loc) · 1.34 KB
/
nist-attenuation-scraper.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
"""
Get some data from NIST
"""
from BeautifulSoup import BeautifulSoup
import urllib2
import matplotlib.pylab as plt
URL = 'http://physics.nist.gov/PhysRefData/XrayMassCoef/ComTab/muscle.html'
response = urllib2.urlopen(URL)
html = response.read()
soup = BeautifulSoup(html)
# ascii = soup.find('pre') # extract ASCII formatted table
# for line in ascii:
# print len(str(line).split())
Energy = []
Mu = []
Muen = []
table = soup.find('table')
for row in table.findAll('tr'):
col = row.findAll('td')
if len(str(col).split()) == 3:
Energy.append(col[0].find(text=True))
Mu.append(col[1].find(text=True))
Muen.append(col[2].find(text=True))
print col[1]
plt.loglog(Energy, Mu, label='Mu')
plt.loglog(Energy, Muen, label='Muen')
plt.title(soup.title(text=True))
plt.legend()
plt.show()
URL = 'http://physics.nist.gov/PhysRefData/XrayMassCoef/ComTab/bone.html'
response = urllib2.urlopen(URL)
html = response.read()
soup = BeautifulSoup(html)
Energy = []
Mu = []
Muen = []
table = soup.find('table')
for row in table.findAll('tr'):
col = row.findAll('td')
if len(str(col).split()) == 3:
Energy.append(col[0].find(text=True))
Mu.append(col[1].find(text=True))
Muen.append(col[2].find(text=True))
asdf = col[1](text=True)
print type(unicode.join(u'\n', map(unicode, asdf)))