自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何用Python來找你喜歡的妹子?

開發(fā) 后端 服務(wù)器
我之前寫了一個抓取妹子資料的文章,主要是使用selenium來模擬網(wǎng)頁操作,然后使用動態(tài)加載,再用xpath來提取網(wǎng)頁的資料,但這種方式效率不高。所以今天我再補一個高效獲取數(shù)據(jù)的辦法.由于并沒有什么模擬的操作,一切都可以人工來控制,所以也不需要打開網(wǎng)頁就能獲取數(shù)據(jù)!

先上效果圖吧,no pic say bird!

 

我之前寫了一個抓取妹子資料的文章,主要是使用selenium來模擬網(wǎng)頁操作,然后使用動態(tài)加載,再用xpath來提取網(wǎng)頁的資料,但這種方式效率不高。

所以今天我再補一個高效獲取數(shù)據(jù)的辦法.由于并沒有什么模擬的操作,一切都可以人工來控制,所以也不需要打開網(wǎng)頁就能獲取數(shù)據(jù)!

但我們需要分析這個網(wǎng)頁,打開網(wǎng)頁 http://www.lovewzly.com/jiaoyou.html 后,按F12,進入Network項中

url在篩選條件后,只有page在發(fā)生變化,而且是一頁頁的累加,而且我們把這個url在瀏覽器中打開,會得到一批json字符串,所以我可以直接操作這里面的json數(shù)據(jù),然后進行存儲即可!

代碼結(jié)構(gòu)圖:

操作流程

  • headers 一定要構(gòu)建反盜鏈以及模擬瀏覽器操作,先這樣寫,可以避免后續(xù)問題!
  • 條件拼裝
  • 然后記得數(shù)據(jù)轉(zhuǎn)json格式
  • 然后對json數(shù)據(jù)進行提取,
  • 把提取到的數(shù)據(jù)放到文件或者存儲起來

主要學習到的技術(shù):

  • 學習requests+urllib
  • 操作execl
  • 文件操作
  • 字符串
  • 異常處理
  • 另外其它基礎(chǔ)

請求數(shù)據(jù):

  1. def craw_data(self): 
  2.         '''數(shù)據(jù)抓取''' 
  3.         headers = { 
  4.             'Referer''http://www.lovewzly.com/jiaoyou.html'
  5.             'User-Agent''Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.4620.400 QQBrowser/9.7.13014.400' 
  6.         } 
  7.         page = 1 
  8.         while True
  9.  
  10.             query_data = { 
  11.                 'page':page, 
  12.                 'gender':self.gender, 
  13.                 'starage':self.stargage, 
  14.                 'endage':self.endgage, 
  15.                 'stratheight':self.startheight, 
  16.                 'endheight':self.endheight, 
  17.                 'marry':self.marry, 
  18.                 'salary':self.salary, 
  19.             } 
  20.             url = 'http://www.lovewzly.com/api/user/pc/list/search?'+urllib.urlencode(query_data) 
  21.             print url 
  22.             req = urllib2.Request(url, headers=headers) 
  23.             response = urllib2.urlopen(req).read() 
  24.             # print response 
  25.             self.parse_data(response) 
  26.             page += 1 

字段提?。?/p>

  1. def parse_data(self,response): 
  2.       '''數(shù)據(jù)解析''' 
  3.       persons = json.loads(response).get('data').get('list'
  4.       if persons is None: 
  5.           print '數(shù)據(jù)已經(jīng)請求完畢' 
  6.           return 
  7.  
  8.       for person in persons: 
  9.           nick = person.get('username'
  10.           gender = person.get('gender'
  11.           age = 2018 - int(person.get('birthdayyear')) 
  12.           address = person.get('city'
  13.           heart = person.get('monolog'
  14.           height = person.get('height'
  15.           img_url = person.get('avatar'
  16.           education = person.get('education'
  17.           print nick,age,height,address,heart,education 
  18.           self.store_info(nick,age,height,address,heart,education,img_url) 
  19.           self.store_info_execl(nick,age,height,address,heart,education,img_url) 

文件存放:

  1. def store_info(self, nick,age,height,address,heart,education,img_url): 
  2.         ''
  3.         存照片,與他們的內(nèi)心獨白 
  4.         ''
  5.         if age < 22: 
  6.             tag = '22歲以下' 
  7.         elif 22 <= age < 28: 
  8.             tag = '22-28歲' 
  9.         elif 28 <= age < 32: 
  10.             tag = '28-32歲' 
  11.         elif 32 <= age: 
  12.             tag = '32歲以上' 
  13.         filename = u'{}歲_身高{}_學歷{}_{}_{}.jpg'.format(age,height,education, address, nick) 
  14.  
  15.         try: 
  16.             # 補全文件目錄 
  17.             image_path = u'E:/store/pic/{}'.format(tag) 
  18.             # 判斷文件夾是否存在。 
  19.             if not os.path.exists(image_path): 
  20.                 os.makedirs(image_path) 
  21.                 print image_path + ' 創(chuàng)建成功' 
  22.  
  23.             # 注意這里是寫入圖片,要用二進制格式寫入。 
  24.             with open(image_path + '/' + filename, 'wb'as f: 
  25.                 f.write(urllib.urlopen(img_url).read()) 
  26.  
  27.             txt_path = u'E:/store/txt' 
  28.             txt_name = u'內(nèi)心獨白.txt' 
  29.             # 判斷文件夾是否存在。 
  30.             if not os.path.exists(txt_path): 
  31.                 os.makedirs(txt_path) 
  32.                 print txt_path + ' 創(chuàng)建成功' 
  33.  
  34.             # 寫入txt文本 
  35.             with open(txt_path + '/' + txt_name, 'a'as f: 
  36.                 f.write(heart) 
  37.         except Exception as e: 
  38.             e.message 

execl操作:

  1. def store_info_execl(self,nick,age,height,address,heart,education,img_url): 
  2.        person = [] 
  3.        person.append(self.count)   #正好是數(shù)據(jù)條 
  4.        person.append(nick) 
  5.        person.append(u'女' if self.gender == 2 else u'男'
  6.        person.append(age) 
  7.        person.append(height) 
  8.        person.append(address) 
  9.        person.append(education) 
  10.        person.append(heart) 
  11.        person.append(img_url) 
  12.  
  13.        for j in range(len(person)): 
  14.            self.sheetInfo.write(self.count, j, person[j]) 
  15.  
  16.        self.f.save(u'我主良緣.xlsx'
  17.        self.count += 1 
  18.        print '插入了{}條數(shù)據(jù)'.format(self.count

***展現(xiàn)!

源碼地址:https://github.com/pythonchannel/python27/blob/master/test/meizhi.py

責任編輯:武曉燕 來源: 養(yǎng)碼場
相關(guān)推薦

2011-12-13 14:44:41

51CTO

2018-03-27 18:12:12

PythonHTML

2017-06-29 11:11:17

2020-07-10 09:49:53

數(shù)據(jù)清理數(shù)據(jù)分析查找異常

2023-02-08 07:09:40

PythonChatGPT語言模型

2019-10-22 08:42:59

AI 數(shù)據(jù)人工智能

2012-09-19 13:03:00

2019-11-28 09:23:17

Python機器學習數(shù)據(jù)庫

2018-05-17 10:05:24

運行iPadPython

2020-05-09 10:38:31

Python透視表數(shù)據(jù)

2021-03-04 13:40:57

Python文件代碼

2020-12-10 10:46:23

PythonExcel圖片

2013-02-26 10:28:00

項目管理項目經(jīng)理時間管理

2018-12-06 08:40:43

PythonR函數(shù)編程語言

2019-12-26 09:28:34

TCPPython通信

2020-09-25 08:40:02

Python開發(fā)網(wǎng)絡(luò)

2020-11-06 17:42:02

Python開發(fā)工具

2021-06-02 15:10:20

PythonScrapy視頻

2020-10-22 10:15:33

優(yōu)化Windows電腦

2019-08-01 15:08:37

PythonLine操作系統(tǒng)
點贊
收藏

51CTO技術(shù)棧公眾號