如何获得Google的“快速解答框"文本? [英] How to get googles "fast answer box" text?

查看:78
本文介绍了如何获得Google的“快速解答框"文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取Google的快速解答框"文本.访问屏幕截图时,我所说的快速回答框"应该清楚:

I'm trying to get googles "fast answer box" text. What I mean by "fast answer box" should be clear on visiting the screenshot:

如果您输入搜索内容并且Google知道答案,则Google会显示此框.因此,您无需打开下面显示的链接之一.如果输入以下查询,则会显示该框:

This Box is shown by google if you enter a search and google knows the answer. So you don't need to open one of the links shown below. The box is shown if you enter following query:

https://google.de/search?q=definition%20calcium

现在,我想通过python脚本阅读此文本.我编写了一种使用请求和精美汤料来实现此目的的方法:

Now I want to read this text via python script. I write a method which uses requests and beautiful soup to achieve this:

def execute(self):
    response = requests.get(url='https://google.de/search?q=definition%20calcium', proxies=self._proxy)
    soup = BeautifulSoup(response.content, 'html.parser')
    return soup.find_all("ol", class_="lr_dct_sf_sens")

该方法始终返回[],表示一个空列表.但是,如果我使用chrome控制台,我可以准确找到这个术语:

The Method always returns [], which means an empty list. But if I use chrome console I can find exactly this term:

所以我不明白为什么找不到它.为了进行测试,我使用以下命令将requests.get的全部内容写入文件:

So I can't understand why this can't be found. For testing I write the whole content from requests.get into a file with this:

file = open('C:\\Users\\me\\Desktop\\test.txt', 'w')
file.write(response.text)
file.close()

试图用记事本搜索文件,但我也找不到那里的搜索模式.不知道response.text是否削减了一些细节.

Tried to search the file with notepad but I can't the search pattern there as well. Not sure if response.text cuts some details.

有人在外面,谁可以向我解释一下?我如何获得此文字?

Is someone out there, who can explain this to me? How can I get this text?

推荐答案

如果在加载该页面时密切关注网络请求,您会发现Google触发了另一个包含您数据的链接.

If you watch closely on your Network requests when loading that page you'll see that google fires up another link which contains your data.

请尝试在浏览器中访问它:

Please try to access this in your browser:

https://www.google.com/search?q=definition:+calcium&bav=on.2,or.r_cp.&cad=b&fp=1&biw=1920&bih=984&dpr=1&tch=1&ech=1&psi=1489578048971.3

它将下载一个文件,上面有您的快速箱数据.您可以在该文件中搜索the chemical element of atomic number进行验证.

It'll download a file on which your fastbox data is available. You can search in that file for the chemical element of atomic number to verify this.

您将必须清理文件并抓取所需的数据.

You'll have to clean the file and scrape the data that you want.

这篇关于如何获得Google的“快速解答框"文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆