擅长:python、mysql、java
<p>你的代码在我这方面运行得很好。您只需在<code>url</code>和<code>loc</code>之前添加:<code>{http://www.sitemaps.org/schemas/sitemap/0.9}</code></p>
<p>这里:</p>
<pre><code>import os.path
import xml.etree.ElementTree
import requests
from subprocess import call
def creatingListOfBrokenLinks():
if (os.path.isfile('sitemap.xml')):
e = xml.etree.ElementTree.parse('sitemap.xml').getroot()
file = open("all_broken_links.txt", "w")
for atype in e.findall('{http://www.sitemaps.org/schemas/sitemap/0.9}url'):
r = requests.get(atype.find('{http://www.sitemaps.org/schemas/sitemap/0.9}loc').text)
print(atype)
if (r.status_code == 404):
file.write(atype)
file.close()
if __name__ == "__main__":
creatingListOfBrokenLinks()
</code></pre>