所以我是从左侧窗格中,你可以看到所有的印度各邦刮这个印度天气网站一些问题与网络刮IMD网站
http://202.54.31.7/citywx/localwx.php
所以,如果你将鼠标悬停在他们,你可以选择城市/区。所以我选择了Delhi->safdarjung
从左侧窗格中,并在本地保存该页面为: -
from BeautifulSoup import BeautifulSoup
import urllib, urllib2
imd_ind = urllib2.urlopen('http://202.54.31.7/citywx/localwx.php')
delhi_info = imd_ind.read()
open('delhi_info.html', 'w').write(delhi_info)
soup = BeautifulSoup(open('delhi_info.html'))
soup.prettify
只打印这么多: -
<bound method BeautifulSoup.prettify of <html><head><title>Local Weather Forecast</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="MSHTML 5.00.2920.0" name="GENERATOR" /></head>
<frameset border="0" cols="330,611*" frameborder="NO" framespacing="0" rows="*"><frame name="menuFrame" noresize="noResize" src="menu.php" /><frame name="mainframe" src="http://202.54.31.7/citywx/city_weather1.php?id=42182" /></frameset></html>
>
而如果我检查本地保存的页面“delhi_info.html”铬,我可以看到很多信息日期,温度,阴天等等(即很多),但为什么我不能通过任何BeautifulSoup方法看到它们。 请帮忙
在关闭写入文件之前,您正在打开文件进行读取,因此某些内容很可能仍然被缓存,并且尚未写入磁盘。试试:'用open('delhi_info.html','w')来代替f:f.write(delhi_info)'。 – isedev 2014-09-30 11:41:02
谢谢isedev,那我应该怎么做来纠正它。请帮忙!! – shalini 2014-09-30 11:45:01
不,即使你打印出内容“delhi_info”,你也会得到相同的结果。 – ton1c 2014-09-30 11:48:09