Advertisement
doubledare704

Untitled

Dec 4th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3.  
  4. url = "https://artifact.gamepedia.com/Cards"
  5.  
  6. r = requests.get(url)
  7.  
  8. data = r.text
  9.  
  10. soup = BeautifulSoup(data, "lxml")
  11.  
  12. numbers = 310
  13. cards = False
  14.  
  15. names = []
  16. names_to_links = []
  17. for link in soup.find_all('a'):
  18.     if link.get('title') == 'Axe':
  19.         cards = True
  20.  
  21.     if cards:
  22.         names.append(link['title'])
  23.         names_to_links.append({
  24.             "name": link['title'],
  25.             "href": link['href']
  26.         })
  27.         numbers -= 1
  28.  
  29.     if numbers < 1:
  30.         cards = False
  31.  
  32. images = []
  33. for img in soup.find_all('img'):
  34.     for n in names:
  35.         if img.get('alt') and n in img.get('alt'):
  36.             images.append({
  37.                 "name": n,
  38.                 "srcset": img.get('srcset'),
  39.                 "src": img.get('src')
  40.             })
  41.  
  42. print(names)
  43. print(names_to_links)
  44. print(images)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement