python中通过BeautifulSoup提取特定标记的值
我有一个简单的python脚本,如:python中通过BeautifulSoup提取特定标记的值,python,beautifulsoup,Python,Beautifulsoup,我有一个简单的python脚本,如: #!/usr/bin/python import requests import BeautifulSoup response = requests.get('http://site.ir/') out=response.content soup = BeautifulSoup.BeautifulSoup(out) for anchor in soup.select('body a'): print anchor.string 但出现以下错误:
#!/usr/bin/python
import requests
import BeautifulSoup
response = requests.get('http://site.ir/')
out=response.content
soup = BeautifulSoup.BeautifulSoup(out)
for anchor in soup.select('body a'):
print anchor.string
但出现以下错误:
File "p.py", line 11, in <module>
for anchor in soup.select('body a'):
TypeError: 'NoneType' object is not callable
文件“p.py”,第11行,在
对于汤中的锚。选择('body a'):
TypeError:“非类型”对象不可调用
图片:
安装BeautifulSoup4并执行以下操作:
import requests
from bs4 import BeautifulSoup
soup = BeautifulSoup(requests.get('http://site.ir/').content)
for anchor in soup.select('body a'):
print anchor.text
我将删除我的答案,因为你一直在更改问题;它不再有效。您正在使用BeautifulSoup 3尝试使用BeautifulSoup 4功能。您查看了返回的内容吗?@Martijn Pieters谢谢您。。。你能给出新的答案吗?我不知道3和4之间的区别,请原谅让你很忙…@Padraic Cunningham它返回了你在帖子中看到的错误,我是说你的html返回了,我不认为它返回了你认为它是什么