Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中从结果中获取指定单词后的动态数字并存储在数据库中_Python_Web Crawler - Fatal编程技术网

在python中从结果中获取指定单词后的动态数字并存储在数据库中

在python中从结果中获取指定单词后的动态数字并存储在数据库中,python,web-crawler,Python,Web Crawler,嗨,我想得到结果中“citedby”后面的数字。每次搜索数字都会改变` import scholarly import re m = next(scholarly.search_pubs_query('Perception of physical stability and center of mass of 3D objects')) n = re.search('citedby (\d+)', m , re.IGNORECASE)` 我用scholarly查找了引文,并存储在m变量中。现

嗨,我想得到结果中“citedby”后面的数字。每次搜索数字都会改变`

import scholarly
import re

m = next(scholarly.search_pubs_query('Perception of physical stability and center of mass of 3D objects'))
n = re.search('citedby (\d+)', m , re.IGNORECASE)`
我用scholarly查找了引文,并存储在m变量中。现在我想得到“citedby”后面的数字:34567。示例现在我想得到“citedby”后面的34567:。请帮助我,我是python新手。添加了示例结果。 ,

您可以尝试使用它作为字符串列表返回字符串中模式的所有非重叠匹配项

import re
m = "Example text 'citedby':34567"  # just an example.
n = re.findall(r"'citedby':\s?(\d+)", m, re.IGNORECASE)
print(' '.join(n))  # 34567
关于你的具体问题:

import scholarly
import re

m = next(scholarly.search_pubs_query('Perception of physical stability and center of mass of 3D objects'))
n = re.findall(r"'citedby':\s?(\d+)", str(m), re.IGNORECASE)
print(''.join(n))  # 13

注意:这里的
m
对象<代码>str(m)使其成为
findall
仅对字符串有效。

好的,先生。如何打印它工作正常,先生。但是当我添加原始结果m=m=next时,它不工作(学术性的。搜索公开查询(“对物理稳定性和三维物体质心的感知”)。输入是否与上图中给出的相同?是的,先生。图像是m变量Ok,我怀疑
后面是否有空格。尝试更新的一个。让我看看。