Advertisement
Guest User

scraper

a guest
Apr 11th, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. from bs4 import BeautifulSoup
  2. import requests
  3. from requests import session
  4.  
  5. login_page = "http://forums.somethingawful.com/account.php?action=loginform#form"
  6. url = "http://forums.somethingawful.com/query.php?action=posthistory&userid=35304&page="
  7. USERNAME = ''
  8. PASSWORD = ''
  9. payload = {
  10.     'action': 'login',
  11.     'username': USERNAME,
  12.     'password': PASSWORD
  13. }
  14. """with session() as c:
  15.     for x in range(1,101):
  16.         c.post(login_page, data=payload)
  17.         response = c.get(url+x)
  18.         soup = BeautifulSoup(response.text, 'html.parser')
  19.         mydivs = soup.findAll("div", {"class" : "blurb"})
  20.         my_file = open("tori.txt", "a")
  21.         for div in mydivs:
  22.             my_file.write(div.string + "\n")
  23.         my_file.close() """
  24. with session() as c:
  25.     c.post(login_page, data = payload)
  26.     for x in range(1,101):
  27.         response = c.get(url + str(x))
  28.         soup = BeautifulSoup(response.text, 'html.parser')
  29.         mydivs = soup.findAll("div", {"class" : "blurb"})
  30.         my_file = open("tori.txt", "a")
  31.         my_file.write("\n" + "\n" + "\n" + "\n" + "Page number: " + str(x) + "\n" + "\n" + "\n" + "\n")
  32.         for div in mydivs:
  33.             if "[quote=" not in div.string:
  34.                 my_file.write(div.string + "\n")
  35.             else:
  36.                 my_file.write("\n")
  37.         my_file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement