Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,29 @@ def exclude_url(exclude, link):
crawling = tocrawl.pop()

url = urlparse(crawling)
crawled.add(crawling)
try:
request = Request(crawling, headers={"User-Agent":'Sitemap crawler'})
response = urlopen(request)
if response.getcode() in responseCode:
responseCode[response.getcode()]+=1
else:
responseCode[response.getcode()] = 0
responseCode[response.getcode()] = 1
if response.getcode()==200:
msg = response.read()
else:
msg = ""
response.close()
continue

response.close()
except Exception as e:
if arg.debug:
logging.debug ("{1} ==> {0}".format(e, crawling))
continue


print ("<url><loc>"+url.geturl()+"</loc></url>", file=output_file)
output_file.flush()
links = linkregex.findall(msg)
crawled.add(crawling)
for link in links:
link = link.decode("utf-8")
if link.startswith('/'):
Expand All @@ -173,7 +175,6 @@ def exclude_url(exclude, link):
target_extension = os.path.splitext(parsed_link.path)[1][1:]

if (link not in crawled) and (link not in tocrawl) and (domain_link == target_domain) and can_fetch(arg.parserobots, rp, link,arg.debug) and ("javascript:" not in link) and (target_extension not in arg.skipext) and (exclude_url(arg.exclude, link)):
print ("<url><loc>"+link+"</loc></url>", file=output_file)
tocrawl.add(link)
print (footer, file=output_file)

Expand Down