祝大家日安! 我正在尝试用ElementTree加载一个.xml文件,代码如下: data = []
root = et.fromstring(r.content)
user = root.findall('.//user')
for u in user:
data.append(
{'id': u.get('id'),
'firstName': u.find('firstName').text,
我试着从亚马逊上获取信息,但我得到了一个AttributeError。代码如下: title = soup.find(id="productTitle").get_text()
price = soup.find(id="priceblock_ourprice").get_text()
'NoneType' object has no attribute 'get_text'
我正在使用漂亮的汤,我得到了一个错误,"AttributeError:'NoneType‘对象没有’get_text‘属性“,还有"TypeError:'NoneType’对象不可订阅”。
我知道当我使用我的代码来搜索一家餐厅时,它是有效的。然而,当我尝试为所有的餐厅做一个循环时,我得到了一个错误。
这是我的屏幕记录,显示了问题。
其余的代码可以在这里找到:
# AttributeError: 'NoneType' object has no attribute 'get_text'
restaurant_address = ye
这是我的代码:
enter code here
import urllib.request
import re
from bs4 import BeautifulSoup
URLdict=dict()
class M1905:
def __init__(self,baseurl):
self.baseURL=baseurl
self.user_agent = 'Chrome/58.0(compatible;MSIE 5.5; Windows 10)'
self.headers = {'User-Agent': s
我能够成功地刮这个网站,但现在它不能正常工作。我现在收到了“温度”变量的错误。
这些变量起作用..。
period_names = [item.find(class_='period-name').get_text() for item in items]
short_descriptions = [item.find(class_='short-desc').get_text() for item in items]
这个变量曾经起作用..。现在没有了。
temperatures = [item.find(class_='temp').get
我有一个对象myobject,它可能返回None。如果返回None,则不会返回属性id
a = myobject.id
因此,当myobject为None时,上面的字符串会产生一个AttributeError
AttributeError: 'NoneType' object has no attribute 'id'
如果myobject为None,那么我希望a等于None。如何在一行语句中避免此异常,例如:
a = default(myobject.id, None)