AttributeError:'str'对象没有属性'text'

时间:2018-03-31 23:19:35

标签: python

我收到了这个错误,有人可以告诉我哪里出错了。

import requests
import time
with open("C:\\temp\\cars.txt", 'r') as myfile:
  data1 = myfile.read()

searchKey = "ford="
searchEndKey = '"' 
auto = data1.text[data1.text.find(searchKey) + len(searchKey):
                  data1.text.find(searchEndKey, data1.text.find(searchKey) + 
                                                len(searchKey) + 1)]

with open("C:\\temp\\cars2.txt", "rt") as fin:
    with open("C:\\temp\\cars3.txt", "wt") as fout:
        for line in fin:
            fout.write(line.replace('ford=', 'ford='+auto))
  

AttributeError:'str'对象没有属性'text'

1 个答案:

答案 0 :(得分:1)

如上所述,删除了.text 现在工作