编写网络机器人的最佳编程语言是哪种? [英] Which is the best programming language to write a web bot?

查看:66
本文介绍了编写网络机器人的最佳编程语言是哪种?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道哪种编程语言提供了很多库来对Web bot进行编程? 类似于抓取网页以获取数据.假设我要获取weather.yahoo.com网站的天气.

I want know which programming language provides good number of libraries to program a web bot? Something like crawling a web page for data. Say I want fetch weather for weather.yahoo.com website.

AI桌面机器人的答案也一样吗?

Also will the answer be same for a AI desktop bot?

推荐答案

这是在Python中的方法:

Here is how you could do it in Python:

from urllib2 import urlopen
from BeautifulSoup import BeautifulSoup
soup=BeautifulSoup(urlopen("http://weather.yahoo.com/").read())
for x in soup.find(attrs={"id":"myLocContainer"}).findAll("li"):
  print x.a["title"], x.em.contents

打印:

美国伊利诺伊州芝加哥市(阴霾)[u'35 ... 47° F']的完整预测
伦敦,大伦敦,英格兰(小雨)[u'43 ... 45° F']
的完整天气预报 美国纽约州(部分多云)[u'42 ... 62° F']
美国加利福尼亚州旧金山(部分多云)的完整天气预报[u'51 ... 70° F']

Full forecast for Chicago, Illinois, United States (Haze) [u'35...47 °F']
Full forecast for London, Greater London, England (Light Rain) [u'43...45 °F']
Full forecast for New York, New York, United States (Partly Cloudy) [u'42...62 °F']
Full forecast for San Francisco, California, United States (Partly Cloudy) [u'51...70 °F']

这篇关于编写网络机器人的最佳编程语言是哪种?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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