我一直在尝试学习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 ×1