I'm trying to pass a list of gene ids to url. gl
stores a list of gene ids. I need "?term="
to iterate over the elements in the list and perform the function defined.
import re
import urllib2
def sr():
gl = [6323,6513]
# need to pass the list gl here:
s = urllib2.urlopen('http://www.ncbi.nlm.nih.gov/gene/?term=','r')
h = s.read()
s.close()
acc = re.search('gi=(.+?)&',h)
if acc:
ac = acc.group(1)
f = open("E:/t.txt", "w")
f.write(ac);
f.close()
I'm not positive I understand what you're looking for, but perhaps urllib.urlencode
is what you're looking for? urlencode
will generate a query string. You can pass this, along with the base URL to urllib.urlopen
.
I'm assuming the values for term
are supposed to be comma-delimited?
gl = [6323,6513]
params = urllib.urlencode({"term": ','.join(map(str, gl))})
s urllib.urlopen('http://www.ncbi.nlm.nih.gov/gene/', params)
As Peter Cock mentioned in the comments, you're better off using Entrez, NCBI's official API ( guide here ). Bio.Entrez
provides a nice interface.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.