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

我只是一个虾纸丫 提交于 2019-11-29 15:18:14

问题


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?


回答1:


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




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/4211059/which-is-the-best-programming-language-to-write-a-web-bot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!