Advertisement
Huskymeister

Deahtsnack's Scrape script.

Mar 4th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. # import libraries
  2. from urllib.request import urlopen, Request
  3. from bs4 import BeautifulSoup
  4.  
  5. # Deathsnacks url including Warframe alert information
  6. wf_quote = 'https://deathsnacks.com/wf/'
  7.  
  8. # Header to be able to access the server as a user
  9. hdr = {'User-Agent': 'Mozilla/5.0'}
  10. req = Request(wf_quote, headers=hdr)
  11.  
  12. # Open the page
  13. wf_page = urlopen(req)
  14.  
  15. # Parse the HTML into an object
  16. soup = BeautifulSoup(wf_page, 'html.parser')
  17.  
  18. # Find the contents of the alert table using what I had found to be unique
  19. alert_table = soup.find_all('li', class_='list-group-item')
  20.  
  21. # Open a file for use to store alert data.
  22. f = open("alert_data.txt", "w")
  23.  
  24. # Read through the search results, grabbing the first 3 elements, since there are only ever 3 alerts
  25. count = 1
  26. for x in alert_table:  
  27.     # Write to that file using indents
  28.     f.write(x.prettify())
  29.    
  30.     # Check if the current Alert is 3, if so then break out the loop and end the script
  31.     # If not, add to the counter to write the next alert.
  32.     if count == 3:
  33.         break
  34.     count += 1
  35.  
  36. # Close the file.
  37. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement