开发者

Which is the best programming language to write a web bot? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reo开发者_如何转开发pened, visit the help center for guidance. Closed 12 years ago.

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.

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


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

Prints:

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']


I don't know if it is the best, but Python is definitely pretty good and simple for that.


Another good python library for screen scraping and web crawling is scrapy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜