. Advertisement .
..3..
. Advertisement .
..4..
For the problem “attributeerror: ‘list’ object has no attribute ‘replace’” I tried to fix it, but it doesn’t work and returns the result I want. Here is my program:
kickoff = tree.xpath('//*[@id="page"]/div[1]/div/main/div/article/div/div[1]/section[2]/p[1]/b[1]/text()')
kickoff = kickoff.replace("'", "")
and
AttributeError: 'list' object has no attribute 'replace'
has occurred. I’ve checked the entire command line but still can’t find the mistake.
The cause:
This error happens because above code returns a list but not a string. List does not have the replace function.
Solution:
Putting str before it, you can change it into a string and the code will be handled.
Or you also use this command:
xpath
returns a list. You need to iterate the items.