我有这个密码:
from bs4 import BeautifulSoup
import urllib2
from lxml import html
from lxml.etree import tostring
trees = urllib2.urlopen('http://aviationweather.gov/adds/metars/index? station_ids=KJFK&std_trans=translated&chk_metars=on&hoursStr=most+recent+only&ch k_tafs=on&submit=Submit').read()
soup = BeautifulSoup(open(trees))
print soup.get_text()
item=soup.findAll(id="info")
print item
但是,当我在窗口中键入soup时,它会给我一个错误,当我的程序运行时,它会给我一个非常长的html代码,带有
等等。任何帮助都是很大的。你知道吗
第一个问题在这一部分:
trees
是一个类似文件的对象,无需对其调用open()
,修复它:我们还显式地将
html.parser
设置为底层解析器。你知道吗然后,您需要对要从页面中提取的内容进行具体说明。下面是获取
METAR text
值的示例代码:打印
KJFK 220151Z 20016KT 10SM BKN250 24/21 A3007 RMK AO2 SLP183 T02440206
。你知道吗相关问题 更多 >
编程相关推荐