Reputation: 1373
Please help me. I'm in a desperate need. I'd like to input the unique contents of a website column by column from a csv file and download the outputs for all the columns into one csv file. This is the website and I'd like to download the resulting tables into a csv file. A sample input could be
RNA,cancer,biotin
DNA,lungs,biotin
My input csv file looks like the above mentioned and I'd like to input RNA,DNA once, get the results, save to a csv file, then cancer,lungs, save results to the same csv file, then biotin (not biotin,biotin) and save the results to a csv file. I've tried this so far.
from selenium import webdriver
import os
import time
import sys
from selenium.webdriver.common.keys import Keys
from urllib2 import Request
import urllib2
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir", "path")
fp.set_preference("browser.download.manager.closeWhenDone", True)
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/x-gzip gz")
browser = webdriver.Firefox(firefox_profile=fp)
browser.get("http://bioportal.bioontology.org/annotator")
popup= browser.find_element_by_class_name("close").click()
sinput = browser.find_element_by_id("annotation_text")
sinput.send_keys("cancer")
ontology = browser.find_element_by_class_name("default")
ontology.click()
ontology.send_keys("National Cancer Institute Thesaurus")
ontology.send_keys(Keys.RETURN);
submit = browser.find_element_by_id('annotator_button')
submit.click()
time.sleep(30)
Upvotes: 1
Views: 199
Reputation: 1373
I did this, a part of which is taken from here
time.sleep(2)
clickme = browser.find_elements_by_xpath('//*[@id="annotations"]')
data = []
for tr in clickme:
tds=tr.find_elements_by_tag_name('td')
if tds:
data.append([td.text for td in tds])
def chunks(l, n):
for i in xrange(0, len(l), n):
yield l[i:i+n]
with open('out.csv', 'wb') as csvfile:
csvwriter = csv.writer(csvfile)
for a_chunk in chunks(data[0], 6):
csvwriter.writerow(a_chunk)
browser.close()
Upvotes: 1