通過python獲取論壇使用者資訊的demo

2022-09-01 05:57:12 字數 4186 閱讀 5803

今天寫乙個通過python獲取論壇使用者資訊的demo

有朋友會問,這玩意有啥用麼?用處老大了,舉個栗子,通過獲取到使用者的資訊與本地庫比對,就會獲得n多賬號密碼,不多解釋

爬取乙個ctf的站吧,

先分析  1.會員數量,看圖說話,明顯官網提供的資料不對,自己抓取吧。

2.抓取會員使用者名稱、id、使用者組

通過**對比,使用者組中 管理員與普通使用者的抓取格式不一樣,在**中做了一次判斷,對於 有的會員沒有使用者組,直接就傳空值

抓取後的mysql圖:

看**吧,裡面的細節自己分析自己看!

1

#-- coding: utf-8 --

2import

pymysql

3import

requests

4from lxml import

etree

5 headers=

6class

spiders(object):

7"""

爬取"""

8def

html(self,url):

9"""

"抓取目標網頁原始碼

"""10 html=response=requests.request("

get",url,headers=headers)

11if html.status_code ==200:

12return

response.text

13def

spider(self,html):

14 html1=etree.html(html)

15 title=html1.xpath("

//title/text()")

16try:17

if str(title).find("

個人資料"):

18 username = html1.xpath("

.//h2[@class='mbn']/text()")

19 username = str(str(username[0]).split()).replace("

[","").replace("

]","")20

#對所有的獲取資訊進行去除,()處理,字元格式化

21 id = html1.xpath("

.//span[@class='xw0']/text()")

22 id = str(id).replace("

uid:

", "").replace("

(","").replace("

)","").replace("

[","").replace("

]",""

)23 groups = html1.xpath("

.//ul/li/span/a/text()")

24if len(groups) ==0:

25 groups = html1.xpath("

.//li[2]/span/a/font/text()")

26 groups=str(groups).replace("

[","").replace("

]","")27

#這裡只抓取使用者組和管理組,兩個組的原始碼不一致 ,所以進行判斷28#

print(username)29#

print(id)30#

print(groups)

31except:32

print("

使用者被禁用,忽略")

33 username="";id="";groups=""

34return

id,username,groups

35def

spider_newuser(self):

36 url = "

"37 html=self.html(url)

38 html1 =etree.html(html)39#

new_user = html1.xpath("//title/text()")

40 new_user_id=html1.xpath("

.//div[@id='content1_2']/div[@class='pta st clear'][1]/h4/a/@href")

41 new_user_id=int(str(new_user_id).replace("

space-uid-

","").replace("

.html

","").replace('

[','').replace('

]','').replace("

'",""

))42

return

new_user_id

43class

writeobj(object):

44"""

把爬取資訊寫入mysql

"""45

defwrite_pa(self,id,username,groups):

46 db=pymysql.connect(host="

localhost

",user="

root

",password="

root

",port=3306,db="

dz_spider")

47if id=="":48

return

none

49 cursor=db.cursor()

50 table="

users

"51 data=

56 keys=","

.join(data.keys())

57 values=tuple(data.values())

58 sql=f"

insert into values"59

#print(sql)

60try:61

ifcursor.execute(sql):

62print("

successful")

63db.commit()

64except:65

print("

failed")

66db.rollback()

67db.close()

6869

if__name__ == '

__main__':

70 spiders=spiders()

71 write =writeobj()

72 new_user_id =spiders.spider_newuser()73#

url = f"space-uid-3008.html"

74for i in range(1,new_user_id):

75 url = f"

space-uid-.html

"76 html=spiders.html(url)

77 id,username,groups=spiders.spider(html)

78 write.write_pa(id, username, groups)

通過MediaStore獲取Audio資訊

mediastore中定義了一系列的資料 通過contentresolver提供的查詢介面,我們可以得到各種需要的資訊。下面我們重點介紹查詢sd卡上的 檔案資訊。先來了解一下contentresolver的查詢介面 cursor query uri uri,string projection,str...

通過Nginx獲取使用者ip

x forwarded for,x real ipx forwarded for的格式 x forwarded for client,proxy1,proxy2 說明 client指使用者機的ip,或請求 的最初的機器的ip proxy1指一級 proxy2指二級 例如 x forwarded fo...

通過python獲取微秒時間

import datetime import time print time.time hello datetime.datetime.now print hello s datetime.datetime hello.year,hello.month,hello.day,hello.hour,he...