Hi all``
I am using this code to download pubmed articles
search_url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?
db=pubmed&mindate=2010/01/01&maxdate=2016/12/31&usehistory=y&retmode=json"
search_r = requests.post(search_url)
search_data = search_r.json()
webenv = search_data["esearchresult"]['webenv']
total_records = int(search_data["esearchresult"]['count'])
fetch_url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?
db=pubmed&retmax=9999&query_key=1&webenv="+webenv
for i in range(0, total_records, 10000):
this_fetch = fetch_url+"&retstart="+str(i)
print("Getting this URL: "+this_fetch)
fetch_r = requests.post(this_fetch)
f = open('pubmed_batch_'+str(i)+'_to_'+str(i+9999)+".json", 'w')
f.write(fetch_r.text)
f.close()
I want to have output in XML not in json, the problem is when I want to do this :
page = urllib.urlopen('one of the URLs')
content = page.read()
obj = json.loads(content)
xml = dicttoxml.dicttoxml(content)
print(xml)
I have this error:
No JSON object could be decoded
Ideally If I can extract XML ? and avoid the json outputs which are not recognized as json
PS: ignore the idendation issues due to copy paste
Thanks
I don't understand the issue here. If you want xml output from NCBI, just use retmode=xml in the url.
Already did this and it returns an error
What does return an error ? What's the error message ?
I changed the following:
I got this error:
AttributeError Traceback (most recent call last)
<ipython-input-8-262417e4aa63> in <module>()
db=pubmed&mindate=2010/01/01&maxdate=2016/12/31&usehistory=y&retmode=xml"
----> 3 search_data = search_r.xml()
4 webenv = search_data["esearchresult"]['webenv']
AttributeError: 'Response' object has no attribute 'xml'
I don't know which programming language you're using (python maybe ? I don't know python) but this could indicate that your object has no method called xml. Maybe whatever module you're using is not capable of handling xml. The solution is to deal with the xml yourself, maybe with the help of another module. This looks now more like a programming question and not a bioinformatics one. You may have better luck asking on StackOverflow. Alternatively, explain what you're trying to do, i.e. what bioinformatics problem you're trying to solve. There may already be a solution.