Python-实现一个这样一个功能,请一定看一下我的题目描述

发布于 2016-11-12 03:47:02 字数 162 浏览 1287 评论 1

比如说,我现在想用google搜索一个关键字,但是我不想在网页端输入,我想在本地写一个软件,在这里面提交这个关键字,然后得到提交后的网页源代码。

需求总览:

提交:一个关键字
返回:google搜索后得到的网页网页源码。

我现在真的很急切的需要这个功能

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜柠檬 2017-08-22 19:11:10

嗯...
这不就是一个http get的事么
我用了python-requests

# -*- coding: utf-8 -*-
import requests

def getFromGoogle(key):
proxies={"http":"http://cn-proxy.xxx.com:80"}
url='http://www.google.com/search'
params={'q':key}
r = requests.get(url, params=params, proxies=proxies)
return r.content

#print getFromGoogle('jquery')
print getFromGoogle('老友记')

不用proxy上google的话, 把proxies=proxies去掉

如果楼主想试用图片搜索, 先post图片到http://www.google.com/searchbyimage/upload; 从此post response中拿到location报头; 用此location报头构造一个http get.
Firebug抓到的东西:
先是Post request:

POST /searchbyimage/upload HTTP/1.1
Host: www.google.co.jp
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: https://www.google.co.jp/imghp?hl=en&tab=wi
Cookie: PREF=ID=48c1b49ccc92db73:U=48ef765137ded3f1:FF=0:LD=en:TM=1358317385:LM=1367467206:SG=1:S=R0DZLqc14T6Cj8f8; NID=67=Kb8714K0ffgwwsGjb4EztEDblq1PwSkTXUAweB5bAo-vokfrjE_l6U-ggBxAUS8dAx30lS-tlZ6Tm88SVO455kOHd2AIB6MhEno2X1r1XCo3uPnZCGIZBYLo8k5Uzkyw-75jEylknZ4DlRmSiOYvO57Y9X5fc620hZ-iVgX0vu_YNQ; SID=DQAAAL0AAABwHom4NUS-WJFOJRjdpU4FQYYzc4Pw6FJReRbwyQhOzGrsV4HP3vniAfWuSWs-5dAeRMkOnVWAccRqGBKlWZhK1k5OwCPDy8AQcEnupWvKcRS5uZ28bC9zV0PA1DqYPnQ5sHfPtfZXTW18YKCM6LKSq08ML-XhuzrucklnuKuP3lLbWnahm0lUkQAMDkBvKifFBf-qiBuX1BJuDo5KEJ5QotB34lrMEwVjt0uLSXB_mRBvLaNeX6TrEMq_RX05f6M; HSID=AK4Hvq0AxwK92bqzE; SSID=AWxd1jw95B_gWIkMh; APISID=zmxCHwRqN7Z8gLde/AlRCGe_eA1TFM4vJ6; SAPISID=In1t2vetVlfa1Al1/A21c8uPALvpF3fssb
Connection: keep-alive

Content 略...

Post response:

HTTP/1.1 302 Found
Cache-Control: public, max-age=21600
Content-Length: 1669
Content-Type: text/html; charset=UTF-8
Date: Thu, 02 May 2013 04:00:39 GMT
Expires: Thu, 02 May 2013 10:00:39 GMT
Location: https://www.google.co.jp/search?tbs=sbi:AMhZZityRN9pkVhNN9qCi3mKqdV8PzvI55XCiiMPSZ0bW_1kt67jfcgzA05Vm2XOH-GcHoVEMPUJc_1mJuShx22rXPzHbL69scvE0BTXYPbBrhB3D8uVV90hryEE0KmKISQeJps72ikq_1sidkp89x9PElJYnXGSDjX7Dh_1IWPurV1O3kej5gBy5Fd7liWD_13C-fVMUAGLMxS5SJUU6n2tvNG81RtPSq72JsPzr2XlGGsk25IFtW4_1NleKVLsTflONb-ijMJohT-GIHmBSLmEjhD2eJOre0QOLiymFzbjmYq53RNt3Qr82FRbKu1NkfdLx44MchnuEkwRplYtkZAUb-wa2wOtao58ygOSO6aORANIrla57k12ajs2ly_1yagqIdTnuG6BECKjjYSMBNcWxvQN_1q6DtyyBJXXfcW3PIRlsL-0o0djbulSrzKEYtDgTOQZQtBnYY6KvQVRSDyzloKhx1cb6mkOthzPDKl2DfKfycB4ERKN6Lzk-d9KVyZAKYVkaHKWlTKRG1KvkRgSpRezT4BB4IjbICn9WxGweGt8EO7TBpRdXUxsGxWx1H4roGpawQfim8UG5al32RF9pSp7GrMIDgYsyqMsGGy6sUcJE3xzNLHzvPjjVb1R1WXlEA7I_1BkOtiZNdj3FI5232DICZ3vjwIdCihKU-rZw3goEyuSi4_1Zp_1NpqCFkAJknM03gg5QzTYsbydSrJyo74lKXnT55qQh0fzl2znE1w_1VJppAwLgpuFjgiwfrlco4dUQMd-J7HLGZGIy1keffaqE1ez26HyW6prs9uePCY9ei4ZotKO6vodX_1qbObrvx1BHDftpqnZqKMqcvcjbBlJbTkNBOBV9ERBSvpeTTKPo3mlVflak8LpM5b61tCvKKluxPFqQuJPf7gjwIUxDlB5aOQXjOp-OMddF1lI8QPFDU4W7RkRz_1XIYBYAfZDRSbIEyg3Bm8-MKpC0cRNNaY2nCBaGNjjIrv1_14fiIkF5kJW16chbYS0qhIyZU0Jp92aes1jsufxqySa-sIvRcZNqtXVebQJHX5lUR17-EXQNE1LQNmbBXcej91C070vOmVmnbNDEDWmMW9jB9wc_12oMZg3PXPjTOYKwfEHud6-JFc_1NJNJNFyQzy-1rrLSs6D829mDod5bmZixngiQvjYJNn3gaNj8U3VcASsSAiX1bPi1KXK3ke0BTIO_12GxVkC9YHkH2GZgpeAXSo1ivQfK7-y6bk4UdC_1mHt-Q1VzN8XZ54wRupB0LoGfGeJS-QTC-44LCdyxtJczhNCJDj-SE6KEnlNxqOkqd3oYd0C6JmQqK0cyraNcJcqFo113nTM0JZrOuTu7yAH7NqXbQi7PPEf4tRWP6-DQ34lbcQw-u8DA&hl=en&bih=773&biw=1440
Server: quimby_frontend
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Firefox-Spdy: 3

再来一个get

https://www.google.co.jp/search?tbs=sbi:AMhZZityRN9pkVhNN9qCi3mKqdV8PzvI55XCiiMPSZ0bW_1kt67jfcgzA05Vm2XOH-GcHoVEM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j8U3VcASsSAiX1bPi1KXK3ke0BTIO_12GxVkC9YHkH2GZgpeAXSo1ivQfK7-y6bk4UdC_1mHt-Q1VzN8XZ54wRupB0LoGfGeJS-QTC-44LCdyxtJczhNCJDj-SE6KEnlNxqOkqd3oYd0C6JmQqK0cyraNcJcqFo113nTM0JZrOuTu7yAH7NqXbQi7PPEf4tRWP6-DQ34lbcQw-u8DA&hl=en&bih=773&biw=1440

回复:我想知道~http://images.google.com/searchbyimage/upload 您是怎么看出来的?有什么技巧能教教我么? — bitory
-- firefox 打开google image, 打开firebug,做上传图片操作。看firebug:
-- 本来抓了个屏,不过好像没法上传。你自己试试吧。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文