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.

44 lines
1.7 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=list, exclude_imgs=list, image_root_urls=list,
  7. verifyssl=True, 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 image_root_urls: recognized image root urls on the domain
  18. :param verifyssl: verify website certificate?
  19. :param headers: Send these headers in every request
  20. :param timezone_offset: timezone offset for lastmod tags
  21. :param changefreq: dictionary, where key is site sub url regex, and value is changefreq
  22. :param priorities: dictionary, where key is site sub url regex, and value is priority float
  23. :return:
  24. """
  25. loop = asyncio.get_event_loop()
  26. c = Crawler(root_url, out_file=out_file, out_format=out_format,
  27. maxtasks=maxtasks, exclude_urls=exclude_urls, exclude_imgs=exclude_imgs,
  28. image_root_urls=image_root_urls, verifyssl=verifyssl,
  29. headers=headers, timezone_offset=timezone_offset,
  30. changefreq=changefreq, priorities=priorities)
  31. loop.run_until_complete(c.run())
  32. try:
  33. loop.add_signal_handler(signal.SIGINT, loop.stop)
  34. except RuntimeError:
  35. pass
  36. print('todo_queue:', len(c.todo_queue))
  37. print('busy:', len(c.busy))
  38. print('done:', len(c.done), '; ok:', sum(list(zip(*c.done.values()))[0]) )
  39. print('tasks:', len(c.tasks))