【发布时间】:2014-01-07 10:10:10
【问题描述】:
我想下载以从搜索结果中下载第一个 pdb 文件(下载链接在名称下方给出)。我正在使用 python、selenium 和 beautifulsoup。到目前为止,我已经开发了代码。
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
我的表格没有。
如何下载搜索列表中的第一个文件? (即本例中的 2YGV)
Download link is : /pdb/protein/P32447
【问题讨论】:
-
为我工作。获取
/pdb/explore/explore.do?structureId=2YGV。什么问题?不能下载吗? -
我也知道了,但是如何下载该文件。是我的问题
标签: python selenium beautifulsoup