this is based on calsyslab project
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.

354 lines
14 KiB

  1. __author__ = 'DarkWeb'
  2. # Here, we are importing the auxiliary functions to clean or convert data
  3. from Forums.Utilities.utilities import *
  4. from datetime import date
  5. from datetime import timedelta
  6. import re
  7. # Here, we are importing BeautifulSoup to search through the HTML tree
  8. from bs4 import BeautifulSoup
  9. # This is the method to parse the Description Pages (one page to each topic in the Listing Pages)
  10. def nulled_description_parser(soup):
  11. # Fields to be parsed
  12. topic = "-1" # topic name
  13. user = [] # all users of each post
  14. addDate = [] # all dated of each post
  15. feedback = [] # all feedbacks of each vendor (this was found in just one Forum and with a number format)
  16. status = [] # all user's authority in each post such as (adm, member, dangerous)
  17. reputation = [] # all users's karma in each post (usually found as a number)
  18. sign = [] # all user's signature in each post (usually a standard message after the content of the post)
  19. post = [] # all messages of each post
  20. interest = [] # all user's interest in each post
  21. # Finding the topic (should be just one coming from the Listing Page)
  22. li = soup.find("td", {"class": "thead"}).find('strong')
  23. topic = li.text
  24. topic = re.sub("\[\w*\]", '', topic)
  25. topic = topic.replace(",","")
  26. topic = topic.replace("\n","")
  27. topic = cleanString(topic.strip())
  28. print(topic)
  29. # Finding the repeated tag that corresponds to the listing of posts
  30. # posts = soup.find("form", {"name": "quickModForm"}).findAll('div', {"class": "windowbg"}) + \
  31. # soup.find("form", {"name": "quickModForm"}).findAll('div', {"class": "windowbg2"})
  32. try:
  33. posts = soup.find('table', {"class": "tborder tfixed clear"}).find('td', {"id": "posts_container"}).find_all(
  34. 'div', {"class": "post"})
  35. # print(len(posts))
  36. # For each message (post), get all the fields we are interested to:
  37. for ipost in posts:
  38. # Finding a first level of the HTML page
  39. # post_wrapper = ipost.find('div', {"class": "post_wrapper"}).find('div', {"class": "poster"})
  40. post_wrapper = ipost.find('span', {"class": "largetext"})
  41. # Finding the author (user) of the post
  42. # author = post_wrapper.find('h4')
  43. author = post_wrapper.text.strip()
  44. # print("author " + author)
  45. user.append(cleanString(author)) # Remember to clean the problematic characters
  46. # Finding the status of the author
  47. smalltext = ipost.find('div', {"class": "post_author"})
  48. # Testing here two possibilities to find this status and combine them
  49. if ipost.find('div', {"class": "deleted_post_author"}):
  50. status.append(-1)
  51. interest.append(-1)
  52. reputation.append(-1)
  53. addDate.append(-1)
  54. post.append("THIS POST HAS BEEN REMOVED!")
  55. sign.append(-1)
  56. feedback.append(-1)
  57. continue
  58. # nulled does have membergroup and postgroup
  59. membergroup = smalltext.find('div', {"class": "profile-rank"})
  60. postgroup = smalltext.find('div', {"class": "postgroup"})
  61. if membergroup != None:
  62. membergroup = membergroup.text.strip()
  63. if postgroup != None:
  64. postgroup = postgroup.text.strip()
  65. membergroup = membergroup + " - " + postgroup
  66. else:
  67. if postgroup != None:
  68. membergroup = postgroup.text.strip()
  69. else:
  70. membergroup = "-1"
  71. status.append(cleanString(membergroup))
  72. # print("status " + cleanString(membergroup))
  73. # Finding the interest of the author
  74. # CryptBB does not have blurb
  75. blurb = smalltext.find('li', {"class": "blurb"})
  76. if blurb != None:
  77. blurb = blurb.text.strip()
  78. else:
  79. blurb = "-1"
  80. interest.append(cleanString(blurb))
  81. # Finding the reputation of the user
  82. # CryptBB does have reputation
  83. author_stats = smalltext.find('div', {"class": "author_statistics"})
  84. karma = author_stats.find('strong')
  85. if karma != None:
  86. karma = karma.text
  87. karma = karma.replace("Community Rating: ", "")
  88. karma = karma.replace("Karma: ", "")
  89. karma = karma.strip()
  90. else:
  91. karma = "-1"
  92. reputation.append(cleanString(karma))
  93. # print("karma " + cleanString(karma))
  94. # Getting here another good tag to find the post date, post content and users' signature
  95. postarea = ipost.find('div', {"class": "post_content"})
  96. dt = postarea.find('span', {"class": "post_date"}).text
  97. # dt = dt.strip().split()
  98. dt = dt.strip()
  99. day=date.today()
  100. if "Yesterday" in dt:
  101. yesterday = day - timedelta(days=1)
  102. yesterday = yesterday.strftime('%m-%d-%Y')
  103. stime = dt.replace('Yesterday,','').strip()
  104. date_time_obj = yesterday+ ', '+stime
  105. date_time_obj = datetime.strptime(date_time_obj,'%m-%d-%Y, %I:%M %p')
  106. elif "hours ago" in dt:
  107. day = day.strftime('%m-%d-%Y')
  108. date_time_obj = postarea.find('span', {"class": "post_date"}).find('span')['title']
  109. date_time_obj = datetime.strptime(date_time_obj, '%m-%d-%Y, %I:%M %p')
  110. else:
  111. date_time_obj = datetime.strptime(dt, '%m-%d-%Y, %I:%M %p')
  112. stime = date_time_obj.strftime('%b %d, %Y')
  113. sdate = date_time_obj.strftime('%I:%M %p')
  114. addDate.append(date_time_obj)
  115. # print("date " + str(date_time_obj))
  116. # Finding the date of the post
  117. # date_time_obj = datetime.strptime(dt, '%a %b %d, %Y %I:%M %p')
  118. # smalltext = postarea.find('div', {"class": "flow_hidden"}).find('div', {"class": "keyinfo"})\
  119. # .find('div', {"class": "smalltext"})
  120. # sdatetime = smalltext.text
  121. # sdatetime = sdatetime.replace(u"\xab","") # Removing unnecessary characters
  122. # sdatetime = sdatetime.replace(u"\xbb","") # Removing unnecessary characters
  123. # sdatetime = sdatetime.split("on: ") # Removing unnecessary characters
  124. # sdatetime = sdatetime[1].strip()
  125. # stime = sdatetime[:-12:-1] # Finding the time of the post
  126. # stime = stime[::-1]
  127. # sdate = sdatetime.replace(stime,"") # Finding the date of the post
  128. # sdate = sdate.replace(",","")
  129. # sdate = sdate.strip()
  130. # Covert the date of the post that can be informed as: "12 February 2016", "today", "yesterday". We need
  131. # a date format here as "mm/dd/yyyy"
  132. # addDate.append(convertDate(sdate,"english", crawlerDate) + " " + stime)
  133. # Finding the post
  134. inner = postarea.find('div', {"class": "post_body scaleimages"})
  135. inner = inner.text.strip()
  136. # print(inner)
  137. post.append(cleanString(inner))
  138. # Finding the users's signature
  139. # signature = ipost.find('div', {"class": "post_wrapper"}).find('div', {"class": "moderatorbar"}).find('div', {"class": "signature"})
  140. signature = ipost.find('div', {"class": "signature scaleimages"})
  141. if signature != None:
  142. signature = signature.text.strip()
  143. # print(signature)
  144. else:
  145. signature = "-1"
  146. sign.append(cleanString(signature))
  147. # As no information about users's feedback was found, just assign "-1" to the variable
  148. feedback.append("-1")
  149. except:
  150. if soup.find('td', {"class": "trow1"}).text == " You do not have permission to access this page. ":
  151. user.append("-1")
  152. status.append(-1)
  153. interest.append(-1)
  154. reputation.append(-1)
  155. addDate.append(-1)
  156. post.append("NO ACCESS TO THIS PAGE!")
  157. sign.append(-1)
  158. feedback.append(-1)
  159. # Populate the final variable (this should be a list with all fields scraped)
  160. row = (topic, post, user, addDate, feedback, status, reputation, sign, interest)
  161. # Sending the results
  162. return row
  163. # This is the method to parse the Listing Pages (one page with many posts)
  164. def nulled_listing_parser(soup):
  165. board = "-1" # board name (the previous level of the topic in the Forum categorization tree.
  166. # For instance: Security/Malware/Tools to hack Facebook. The board here should be Malware)
  167. nm = 0 # this variable should receive the number of topics
  168. topic = [] # all topics
  169. user = [] # all users of each topic
  170. post = [] # number of posts of each topic
  171. view = [] # number of views of each topic
  172. addDate = [] # when the topic was created (difficult to find)
  173. href = [] # this variable should receive all cleaned urls (we will use this to do the marge between
  174. # Listing and Description pages)
  175. # Finding the board (should be just one)
  176. board = soup.find('span', {"class": "active"}).text
  177. board = cleanString(board.strip())
  178. # Finding the repeated tag that corresponds to the listing of topics
  179. itopics = soup.find_all('tr', {"class": "inline_row"})
  180. index = 0
  181. for itopic in itopics:
  182. # For each topic found, the structure to get the rest of the information can be of two types. Testing all of them
  183. # to don't miss any topic
  184. # Adding the topic to the topic list
  185. try:
  186. topics = itopic.find('span', {"class": "subject_old"}).find('a').text
  187. except:
  188. topics = itopic.find('span', {"class": "subject_new"}).find('a').text
  189. topics = re.sub("\[\w*\]", '', topics)
  190. topic.append(cleanString(topics))
  191. # Counting how many topics we have found so far
  192. nm = len(topic)
  193. # Adding the url to the list of urls
  194. try:
  195. link = itopic.find('span', {"class": "subject_old"}).find('a').get('href')
  196. except:
  197. link = itopic.find('span',{"class": "subject_new"}).find('a').get('href')
  198. link = cleanLink(link)
  199. href.append(link)
  200. # Finding the author of the topic
  201. ps = itopic.find('div', {"class":"author smalltext"}).find('a').text
  202. author = ps.strip()
  203. user.append(cleanString(author))
  204. # Finding the number of replies
  205. columns = itopic.findChildren('td',recursive=False)
  206. posts = columns[3].text
  207. post.append(cleanString(posts))
  208. # Finding the number of Views
  209. tview = columns[4].text
  210. view.append(cleanString(tview))
  211. # If no information about when the topic was added, just assign "-1" to the variable
  212. #dt = itopic.find('div', {"class": "responsive-hide"}).text.split('»')[1]
  213. #dt = dt.strip()
  214. #date_time_obj = datetime.strptime(dt,'%a %b %d, %Y %I:%M %p')
  215. #addDate.append(date_time_obj)
  216. addDate.append("-1")
  217. index += 1
  218. return organizeTopics("Nulled", nm, topic, board, view, post, user, addDate, href)
  219. # if len(tag) > 0:
  220. #
  221. # # Finding the topic
  222. #
  223. # tds = tds[0].find(tag[0])
  224. # topics = tds.text
  225. # topics = topics.replace(u"\xbb","")
  226. # topics = topics.strip()
  227. # topic.append(cleanString(topics))
  228. #
  229. # # Counting how many topics we have found so far
  230. #
  231. # nm = len(topic)
  232. #
  233. # # Adding the url to the list of urls
  234. #
  235. # link = tds.findAll('a', href=True)
  236. # link = link[0].get('href')
  237. # link = cleanLink(link)
  238. # href.append(link)
  239. #
  240. # # Finding the author of the topic
  241. #
  242. # ps = itopic.find('td', {"class": tag[1]}).find('p').find('a')
  243. # if ps == None:
  244. # ps = itopic.find('td', {"class": tag[1]}).find('p')
  245. # ps = ps.text.replace("Started by ","")
  246. # else:
  247. # ps = ps.text
  248. # author = ps.strip()
  249. # user.append(cleanString(author))
  250. #
  251. # # Finding the number of replies
  252. #
  253. # statistics = itopic.find('td', {"class": tag[2]})
  254. # statistics = statistics.text
  255. # statistics = statistics.split("Replies")
  256. # posts = statistics[0].strip()
  257. # post.append(cleanString(posts))
  258. #
  259. # # Finding the number of Views
  260. #
  261. # views = statistics[1]
  262. # views = views.replace("Views","")
  263. # views = views.strip()
  264. # view.append(cleanString(views))
  265. #
  266. # # As no information about when the topic was added, just assign "-1" to the variable
  267. #
  268. # addDate.append("-1")
  269. #return organizeTopics("TheMajesticGarden", nm, topic, board, view, post, user, addDate, href)
  270. def nulled_links_parser(soup):
  271. # Returning all links that should be visited by the Crawler
  272. href = []
  273. #print(soup.find('table', {"class": "tborder clear"}).find(
  274. # 'tbody').find_all('tr', {"class": "inline_row"}))
  275. listing = soup.find('tbody')
  276. listing=listing.find_all('tr',id=True)
  277. for a in listing:
  278. listing_rows = a.find_all('td')
  279. link = listing_rows[1]
  280. link = link.find('a',{'class':'topic_title'})
  281. link = link['href']
  282. href.append(link)
  283. return href