小编fin*_*arr的帖子

AttributeError: 'NoneType' 对象没有属性 'strip'

我一直在尝试学习Python(目前是requests和beautifulsoup4),我在网上找到了一个教程

问题是我不断收到以下错误,根本无法弄清楚...

任何帮助,将不胜感激!

回溯(最近一次调用):文件“C:\Users\BillyBob\Desktop\Web Scrap.py”,第 14 行,标题 = a.string.strip() AttributeError: 'NoneType' object has no attribute 'strip'

这是我的代码,以防我犯了错误;

import requests
from bs4 import BeautifulSoup

result = requests.get("http://www.oreilly.com/")

c = result.content

soup = BeautifulSoup(c, "html.parser")
samples = soup.find_all("a")
samples[0]

data = {}
for a in samples:
    title = a.string.strip()
    data[title] = a.attrs['href']
Run Code Online (Sandbox Code Playgroud)

python

4
推荐指数
2
解决办法
5万
查看次数

标签 统计

python ×1