简体   繁体   English

用Python做一个简单的Yahoo搜索

[英]Doing a Simple Yahoo Search in Python

I need to write a Python script which, at one point, does a Yahoo web search to find and download a bunch of C source files. 我需要编写一个Python脚本,该脚本可以一次进行Yahoo Web搜索来查找和下载一堆C源文件。 I'm very new to this and I can't figure out how to just get started with doing a simple web search... I've seen a lot of stuff about BOSS but, from my understanding, this is something you need to pay to use? 我对此很陌生,我不知道如何开始进行简单的网络搜索...我已经看到了很多关于BOSS的内容,但是据我所知,这是您需要付费使用? I am not willing to pay for this. 我不愿意为此付出代价。

I've used Python YQL to get some RSS results as follows: 我使用Python YQL来获得一些RSS结果,如下所示:

import yql
y = yql.Public()
result = y.execute('select * from rss where url="http://www.un.org/apps/news/rss/rss_top.asp"');

for row in result.rows:
   print row.get('title')

And this seems to work, but I can't figure out how to just do a normal web search (since the search.web table is apparently gone). 这似乎有效,但我无法弄清楚如何进行正常的网络搜索(因为search.web表显然已经消失)。 A basic working example would be much appreciated. 一个基本的工作示例将非常感谢。

You might want to try it using mechanize , which simulates a browser. 您可能想使用模拟浏览器的mechanize进行尝试。 If you need to clean out some of the crud in the resulting files, use Beautiful Soup. 如果您需要清除生成的文件中的一些crud,请使用Beautiful Soup。

I can't figure out how to just do a normal web search (since the search.web table is apparently gone). 我无法弄清楚如何进行正常的网络搜索(因为search.web表显然已经消失了)。 A basic working example would be much appreciated. 一个基本的工作示例将非常感谢。

You can use Bing as your search provider and use the microsoft.bing.web data table to perform a web search. 您可以使用Bing作为搜索提供程序,并使用microsoft.bing.web数据表执行Web搜索。

A basic example in Python, which prints the titles of the first 10 results for cake , might look like: Python中的一个基本示例,它打印出cake的前10个结果的标题,可能如下所示:

import yql
y = yql.Public()
env = "http://datatables.org/alltables.env"
query = "select * from microsoft.bing.web where query=@query"

results = y.execute(query, {"query": "cake"}, env=env)

for row in results.rows:
    print row.get("Title")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM