对于一个项目,我想从KeGG网站上的许多路径中提取所有的复合名称。单个有机体中所有通路的列表看起来像this。对于每条路径,我提取名称并存储描述。然后我想要得到所有在这个过程中起作用的化合物。在像this这样的网站上可以找到所有关于KeGG途径的信息。我想提取的元素是在复合下面列出的元素。
基本上,我有一组URL和一个非常具体的正则表达式,我想从每个URL中提取出来。我的问题是:什么是最好的/最少的行数/最简单的多线程网络抓取工具来快速完成这项工作?
下面列出了我目前可用的解决方案。我应该去看看scrapy (它更适用于你没有一组urls的项目),或者更确切地说,我应该自己做一些线程的事情?
import pandas as pd
import urllib
from io import StringIO
import re
def get_KeGG_pathways_cpds(organism = 'eco'):
orgURL = 'http://rest.kegg.jp/list/pathway/'
orgStr = urllib.request.urlopen(orgURL + organism).read().decode('utf-8')
orgIO = StringIO(orgStr)
orgDf = pd.read_csv(orgIO, sep='\t', names = ['pway', 'description'])
pathURL = 'http://rest.kegg.jp/get/'
for pway in orgDf.pway:
pathStr = urllib.request.urlopen(pathURL + pway).read().decode('utf-8')
compounds = re.findall('(C[0-9]{5})', pathStr)
print(compounds)
print('-------------------------\n')
return
get_KeGG_pathways_cpds()发布于 2018-10-08 23:11:42
import requests
listed = requests.get('http://rest.kegg.jp/list/pathway/')
listed = listed.text.split('\n') # Remove the last one which is empty
for l in listed:
result = requests.get('http://rest.kegg.jp/get/{}'.format(l.split('\t')[0])
#do_thing_with_result_here(result)
print(result.text)其中显示:入口map00010途径名称糖酵解/糖异生描述糖酵解是…….
以及其余的路径,我不会在这里复制。
https://stackoverflow.com/questions/52702421
复制相似问题