I want to download to download the first pdb file from search result (download link given below name). I am using python, selenium and beautifulsoup. I have developed code till this point.
import urllib2
from BeautifulSoup import BeautifulSoup
from selenium import webdriver
uni_id = "P22216"
# set parameters
download_dir = "/home/home/Desktop/"
url = "http://www.rcsb.org/pdb/search/smart.do?smartComparator=and&smartSearchSubtype_0=UpAccessionIdQuery&target=Current&accessionIdList_0=%s" % uni_id
print "url - ", url
# opening the url
text = urllib2.urlopen(url).read();
#print "text : ", text
soup = BeautifulSoup(text);
#print soup
print
table = soup.find( "table", {"class":"queryBlue"} )
#print "table : ", table
status = 0
rows = table.findAll('tr')
for tr in rows:
try:
cols = tr.findAll('td')
if cols:
link = cols[1].find('a').get('href')
print "link : ", link
if link:
if status==1:
main_url = "http://www.rcsb.org" + link
print "main_url-----", main_url
status = False
browser.click(main_url)
status+=1
except:
pass
I am getting form as None.
How can i download first file in the search list? (i.e. 2YGV in this case)
Download link is : /pdb/protein/P32447