【发布时间】:2018-06-20 21:23:43
【问题描述】:
我在 BeautifulSoup` 中查找 href 值有问题
from urllib import urlopen
from bs4 import BeautifulSoup
import re
html = urlopen("https://www.google.pl/search?q=sprz%C4%99t+dla+graczy&client=ubuntu&ei=4ypXWsi_BcLZwQKGroW4Bg&start=0&sa=N&biw=741&bih=624")
bsObj = BeautifulSoup(html)
for link in bsObj.find("h3", {"class":"r"}).findAll("a"):
if 'href' in link.attrs:
print(link.attrs['href'])
我总是有错误:
"AttributeError: 'NoneType' 对象没有属性 'findAll'
【问题讨论】:
-
谢谢,但它唯一的问题是在堆栈中粘贴代码:) 在脚本中它没问题
-
好的,让我看看
标签: python python-2.7 web-scraping beautifulsoup