Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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_Regex - Fatal编程技术网

Python 不能使用谷歌搜索的正则表达式?

Python 不能使用谷歌搜索的正则表达式?,python,regex,Python,Regex,我想从谷歌搜索中获得符合以下格式的内容 <h3 class="zBAuLc"><div class="BNeawe vvjwJb AP7Wnd">Google</div></h3> Google 如何使这个正则表达式 以下是我尝试过的: import requests, webbrowser import re userResearch = input('Enter what to search:')

我想从谷歌搜索中获得符合以下格式的内容

<h3 class="zBAuLc"><div class="BNeawe vvjwJb AP7Wnd">Google</div></h3>
Google
如何使这个正则表达式

以下是我尝试过的:

import requests, webbrowser
import re

userResearch = input('Enter what to search:')
print('Searching...')

searcher = requests.get("https://www.google.com/search?q="+userResearch)

results = re.findall(r'<h3 class=".+"><div class=".+">.+</div></h3>', searcher.text)


print (results)

导入请求,webbrowser
进口稀土
userResearch=input('输入要搜索的内容:')
打印('正在搜索…')
searcher=requests.get(“https://www.google.com/search?q=“+用户研究)
results=re.findall(r'.+',searcher.text)
打印(结果)

但是re.findall没有返回我所期望的

您没有逃脱
/
。 试试正则表达式:

r'<h3 class=".+"><div class=".+">.+<\/div><\/h3>'
r'.+'

请您指定哪些不适合您,哪些您已经尝试过了?@andymeissner results=re.findall(r'.+',searcher.text),它返回空数组它返回一整页谷歌搜索,但不返回链接。我需要找到标题和链接(例如Apple;Apple.com)@CrownedPig,请相应地编辑您的问题并给出有效的示例。