我正在尝试使用beautifulsoup从html中查找列表中的所有num
import urllib
from BeautifulSoup import *
import re
line = None
url = raw_input('Enter - ')
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html)
# Retrieve all of the anchor tags
tags = soup('span')
for line in tags:
line = line.strip()
numlist = re.findall('[0-9]+' , tags)
print numlist`我得到了回溯:
回溯(最近一次调用):文件"C:\Documents and Settings\new 388\Desktop\PythonSchool\new12.py“,第14行,行= line.strip() TypeError:'NoneType‘对象不可调用
我不明白我为什么要得到回溯。
发布于 2016-03-01 17:41:45
这是因为您试图在漂亮的汤中运行标记类上的脱衣舞。
将第14行改为:
line = line.string.strip()但是,当您正在搜索的标记有多个子元素时,请注意这仍然是空的。Seee 链接到doco上的string方法以获得漂亮的汤
https://stackoverflow.com/questions/35724358
复制相似问题