-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfishbaseScrapping.py
More file actions
46 lines (37 loc) · 1.21 KB
/
Copy pathfishbaseScrapping.py
File metadata and controls
46 lines (37 loc) · 1.21 KB
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
#!/usr/bin/env python3
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
def getSpecies(genus,species):
browser = webdriver.Firefox()
browser.get("https://www.fishbase.se")
time.sleep(5)
genusElem = browser.find_element(By.ID,'acGenus')
speciesElem = browser.find_element(By.ID,'acSpecies')
genusElem.send_keys(genus)
speciesElem.send_keys(species)
speciesElem.submit()
time.sleep(5)
html = browser.page_source
time.sleep(5)
#print(html)
browser.close()
return html
"""
'<!-- Start Prior r -->' in htmlpython
start = html.find('<!-- Start Prior r -->') + len('<!-- Start Prior r -->')
end = html.find('<!-- Start vulnerability-->')
substring = html[start:end]
print(substring)
"""
def getPrior(html):
if '<!-- Start Prior r -->' not in html:
return "No priors for this species"
else:
start = html.find('<!-- Start Prior r -->') + len('<!-- Start Prior r -->')
end = html.find('<!-- Start vulnerability-->')
substring = html[start:end]
start2 = substring.find("Prior r = ") + len("Prior r = ")
end2 = substring.find(", 95%")
prior = substring[start2:end2]
print(prior)