谷歌搜索与python请求库 [英] google search with python requests library

查看:25
本文介绍了谷歌搜索与python请求库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我试过寻找,但所有其他答案似乎都在使用 urllib2)

(I've tried looking but all of the other answers seem to be using urllib2)

我刚刚开始尝试使用请求,但我仍然不太清楚如何从页面发送或请求其他内容.例如,我将有

I've just started trying to use requests, but I'm still not very clear on how to send or request something additional from the page. For example, I'll have

import requests

r = requests.get('http://google.com')

但我现在不知道如何使用显示的搜索栏进行谷歌搜索.我已经阅读了快速入门指南,但我对 HTML POST 等不太熟悉,所以它并不是很有帮助.

but I have no idea how to now, for example, do a google search using the search bar presented. I've read the quickstart guide but I'm not very familiar with HTML POST and the like, so it hasn't been very helpful.

是否有一种干净优雅的方式来完成我的要求?

Is there a clean and elegant way to do what I am asking?

推荐答案

请求概览

Google 搜索请求是一个标准 HTTP GET 命令.它包括与您的查询相关的参数集合.这些参数以名称=值对的形式包含在请求 URL 中,以与号 (&) 字符分隔.参数包括搜索查询和唯一的 CSE ID (cx) 等数据,用于标识发出 HTTP 请求的 CSE.WebSearch 或图像搜索服务返回 XML 结果以响应您的 HTTP 请求.

The Google search request is a standard HTTP GET command. It includes a collection of parameters relevant to your queries. These parameters are included in the request URL as name=value pairs separated by ampersand (&) characters. Parameters include data like the search query and a unique CSE ID (cx) that identifies the CSE that is making the HTTP request. The WebSearch or Image Search service returns XML results in response to your HTTP requests.

首先,您必须在自定义搜索引擎控制面板<中获取您的 CSE ID(cx 参数)/a>

First, you must get your CSE ID (cx parameter) at Control Panel of Custom Search Engine

然后,请参阅 Google Developers 官方网站以了解自定义搜索.

有很多这样的例子:

http://www.google.com/search?
  start=0
  &num=10
  &q=red+sox
  &cr=countryCA
  &lr=lang_fr
  &client=google-csbe
  &output=xml_no_dtd
  &cx=00255077836266642015:u-scht7a-8i

并解释了您可以使用的参数列表.

And there are explained the list of parameters that you can use.

这篇关于谷歌搜索与python请求库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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