小编use*_*744的帖子

python:TypeError:期望的字符串或缓冲区

我有这个代码,从网站解析数据:

f = open('a url')
new = f.read()
derp = re.findall(r'<ol class="lh-192 trendingnow_trend-list fw-b">(.*?)</ol>', new)
line = derp

def striphtml2(data):
    p = re.compile(r'\d')
    return p.sub(' ', data)
new = striphtml2(line)
#removes anything in <>
def striphtml(data):
    p = re.compile(r'<.*?>')
    return p.sub(' ', data)
ninja = striphtml(new)
Run Code Online (Sandbox Code Playgroud)

但每次我运行它,我得到这个:

TypeError: expected string or buffer
Run Code Online (Sandbox Code Playgroud)

我不知道它有什么问题.

python

-1
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×1