Sitemap generator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.6 KiB

4 years ago
4 years ago
  1. import asyncio
  2. import signal
  3. from pysitemap.base_crawler import Crawler
  4. def crawler(
  5. root_url, out_file, out_format='xml',
  6. maxtasks=10, exclude_urls=[], exclude_imgs=[], verifyssl=True,
  7. headers=None, timezone_offset=0, changefreq=None,
  8. priorities=None):
  9. """
  10. run crowler
  11. :param root_url: Site root url
  12. :param out_file: path to the out file
  13. :param out_format: format of out file [xml, txt]
  14. :param maxtasks: max count of tasks
  15. :param exclude_urls: excludable url paths
  16. :param exclude_imgs: excludable img url paths
  17. :param verifyssl: verify website certificate?
  18. :param headers: Send these headers in every request
  19. :param timezone_offset: timezone offset for lastmod tags
  20. :param changefreq: dictionary, where key is site sub url regex, and value is changefreq
  21. :param priorities: dictionary, where key is site sub url regex, and value is priority float
  22. :return:
  23. """
  24. loop = asyncio.get_event_loop()
  25. c = Crawler(root_url, out_file=out_file, out_format=out_format,
  26. maxtasks=maxtasks, exclude_urls=exclude_urls, exclude_imgs=exclude_imgs, verifyssl=verifyssl,
  27. headers=headers, timezone_offset=timezone_offset,
  28. changefreq=changefreq, priorities=priorities)
  29. loop.run_until_complete(c.run())
  30. try:
  31. loop.add_signal_handler(signal.SIGINT, loop.stop)
  32. except RuntimeError:
  33. pass
  34. print('todo_queue:', len(c.todo_queue))
  35. print('busy:', len(c.busy))
  36. print('done:', len(c.done), '; ok:', sum(list(zip(*c.done.values()))[0]) )
  37. print('tasks:', len(c.tasks))