我在使用爬虫的时候明明之前都可以但是现在又不行了?

# confug<'utf-8'>
import urllib.request
from bs4 import BeautifulSoup
import urllib.parse

url = 'https://www.woyaogexing.com/tupian/weimei/2018/56946.html'
req = urllib.request.urlopen ( url )
resp = BeautifulSoup ( url.text, 'html.parse' )
print ( resp )

一开并没有任何的问题后面突然之间就开始报错 AttributeError: 'str' object has no attribute 'text'

 

resp = BeautifulSoup ( url.text, 'html.parse' )

url是字符串没.text属性,

'html.parse'后面少个r

 

应该改为

resp = BeautifulSoup ( req.read().decode('utf-8'), 'html.parser' )

 正确代码如下:{如果对你有帮助,可以给我个采纳吗,谢谢!! 点击我这个回答右上方的【采纳】按钮}。

# confug<'utf-8'>
import urllib.request
from bs4 import BeautifulSoup
import urllib.parse
url = 'https://www.woyaogexing.com/tupian/weimei/2018/56946.html'
req = urllib.request.urlopen ( url )
# resp = BeautifulSoup ( url.text, 'html.parse' )
resp = BeautifulSoup ( req.read().decode('utf-8'), 'html.parser' )
print ( resp )