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.

setbot.py 1008B

12345678910111213141516171819202122232425262728293031323334
  1. #Welcome to setbot, a tool to parse mtg set symbols for user flair on reddit
  2. from pyquery import PyQuery as pq
  3. from lxml import html
  4. import requests
  5. import praw
  6. import urllib
  7. URL = "https://magic.wizards.com/en/products/card-set-archive"
  8. def main():
  9. session_requests = requests.session()
  10. # Scrape rank data from navbar span
  11. result = session_requests.get(URL, headers = dict(referer = URL))
  12. tree = html.fromstring(result.content)
  13. set_list = tree.xpath('//*[string-length(@id) = 3]/div/ul/li[2]/a/span[2]')
  14. # Dunno the syntax for the tool you're using
  15. # But internally all HTML elements are HTML Nodes
  16. # So basically
  17. # groups = getAllNodes('.card-set-archive-table')
  18. # for group in groups
  19. # sets = group.getAllNodes('li.modern-format')
  20. # for set in sets
  21. # imageNode = set.getAllNodes('.icon img')
  22. # imageUrl = imageNode.src
  23. # downloadImage(imageUrl)
  24. print "%s" % set_list
  25. if __name__ == '__main__':
  26. main()