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.

157 lines
6.5 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, ResultSet, Tag
  9. # This is the method to parse the Description Pages (one page to each topic in the Listing Pages)
  10. def cardingleaks_description_parser(soup: Tag):
  11. # Fields to be parsed
  12. topic = "-1" # 0 *topic name
  13. user = [] # 1 *all users of each post
  14. status = [] # 2 all user's authority in each post such as (adm, member, dangerous)
  15. reputation = [] # 3 all user's karma in each post (usually found as a number)
  16. interest = [] # 4 all user's interest in each post
  17. sign = [] # 5 all user's signature in each post (usually a standard message after the content of the post)
  18. post = [] # 6 all messages of each post
  19. feedback = [] # 7 all feedbacks of each vendor (this was found in just one Forum and with a number format)
  20. addDate = [] # 8 all dates of each post
  21. image_user = [] # 9 all user avatars of each post
  22. image_post = [] # 10 all first images of each post
  23. li = soup.find("h1", {"class": "p-title-value"})
  24. topic = cleanString(li.text.strip())
  25. post_list: ResultSet[Tag] = soup.find("div", {"class": "block-body js-replyNewMessageContainer"}).find_all("article", {"data-author": True})
  26. for ipost in post_list:
  27. username = ipost.get('data-author')
  28. user.append(username)
  29. user_status = ipost.find("h5", {"class": "userTitle message-userTitle"}).text
  30. status.append(cleanString(user_status.strip()))
  31. user_statistics: ResultSet[Tag] = ipost.find("div", {"class": "message-userExtras"}).find_all("dl", {"class": "pairs pairs--justified"})
  32. user_reputation = "-1"
  33. for stat in user_statistics:
  34. data_type = stat.find("span").get("data-original-title")
  35. if data_type == "Points":
  36. user_reputation = stat.find("dd").text
  37. break
  38. reputation.append(cleanString(user_reputation.strip()))
  39. interest.append("-1")
  40. sign.append("-1")
  41. user_post = ipost.find("div", {"class": "message-content js-messageContent"}).text
  42. post.append(cleanString(user_post.strip()))
  43. feedback.append("-1")
  44. datetime_text = ipost.find("ul", {"class": "message-attribution-main listInline"}).find("time").get("datetime")
  45. datetime_obj = datetime.strptime(datetime_text, "%Y-%m-%dT%H:%M:%S%z")
  46. addDate.append(datetime_obj)
  47. img = ipost.find('div', {"class": "message-content js-messageContent"}).find('img')
  48. if img is not None:
  49. img = img.get('src').split('base64,')[-1]
  50. else:
  51. img = "-1"
  52. image_post.append(img)
  53. img = ipost.find('div', {"class": "message-avatar"}).find('img')
  54. if img is not None:
  55. img = img.get('src').split('base64,')[-1]
  56. else:
  57. img = "-1"
  58. image_user.append(img)
  59. # Populate the final variable (this should be a list with all fields scraped)
  60. row = (topic, user, status, reputation, interest, sign, post, feedback, addDate, image_user, image_post)
  61. # Sending the results
  62. return row
  63. # This is the method to parse the Listing Pages (one page with many posts)
  64. def cardingleaks_listing_parser(soup: Tag):
  65. nm = 0 # *this variable should receive the number of topics
  66. forum = "Cardingleaks" # 0 *forum name
  67. board = "-1" # 1 *board name (the previous level of the topic in the Forum categorization tree.
  68. # For instance: Security/Malware/Tools to hack Facebook. The board here should be Malware)
  69. author = [] # 2 *all authors of each topic
  70. topic = [] # 3 *all topics
  71. views = [] # 4 number of views of each topic
  72. posts = [] # 5 number of posts of each topic
  73. href = [] # 6 this variable should receive all cleaned urls (we will use this to do the marge between
  74. # Listing and Description pages)
  75. addDate = [] # 7 when the topic was created (difficult to find)
  76. image_user = [] # 8 all user avatars used in each topic
  77. # Finding the board (should be just one)
  78. li = soup.find("h1", {"class": "p-title-value"})
  79. board = cleanString(li.text.strip())
  80. thread_list: ResultSet[Tag] = soup.find("div", {"class": "structItemContainer-group js-threadList"}).find_all("div", {"data-author": True})
  81. nm = len(thread_list)
  82. for thread in thread_list:
  83. thread_author = thread.get("data-author")
  84. author.append(thread_author)
  85. thread_topic = thread.find("div", {"class": "structItem-title"}).text
  86. topic.append(cleanString(thread_topic.strip()))
  87. author_icon = thread.find("a", {"class": "avatar avatar--s"}).find("img")
  88. author_icon = author_icon.get('src')
  89. author_icon = author_icon.split('base64,')[-1]
  90. image_user.append(author_icon)
  91. thread_view = thread.find("dl", {"class": "pairs pairs--justified structItem-minor"}).find("dd").text
  92. # Context text view count (i.e., 8.8K) to numerical (i.e., 8800)
  93. if thread_view.find("K") > 0:
  94. thread_view = str(int(float(thread_view.replace("K", "")) * 1000))
  95. views.append(thread_view)
  96. thread_posts = thread.find("dl", {"class": "pairs pairs--justified"}).find("dd").text
  97. posts.append(cleanString(thread_posts.strip()))
  98. thread_href = thread.find("div", {"class": "structItem-title"}).find("a").get("href")
  99. href.append(thread_href)
  100. thread_date = thread.find("li", {"class": "structItem-startDate"}).find("time").get("datetime")
  101. datetime_obj = datetime.strptime(thread_date, "%Y-%m-%dT%H:%M:%S%z")
  102. addDate.append(datetime_obj)
  103. return organizeTopics(forum, nm, board, author, topic, views, posts, href, addDate, image_user)
  104. def cardingleaks_links_parser(soup):
  105. # Returning all links that should be visited by the Crawler
  106. href = []
  107. listing = soup.find_all('div', {"class": "structItem-title"})
  108. for a in listing:
  109. link = a.find('a').get('href')
  110. href.append(link)
  111. return href