成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

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

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

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

 

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

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

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

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

代碼結構圖:

操作流程

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

主要學習到的技術:

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

請求數據:

  1. def craw_data(self): 
  2.         '''數據抓取''' 
  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 

字段提取:

  1. def parse_data(self,response): 
  2.       '''數據解析''' 
  3.       persons = json.loads(response).get('data').get('list'
  4.       if persons is None: 
  5.           print '數據已經請求完畢' 
  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.         存照片,與他們的內心獨白 
  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 + ' 創建成功' 
  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'內心獨白.txt' 
  29.             # 判斷文件夾是否存在。 
  30.             if not os.path.exists(txt_path): 
  31.                 os.makedirs(txt_path) 
  32.                 print txt_path + ' 創建成功' 
  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)   #正好是數據條 
  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 '插入了{}條數據'.format(self.count

***展現!

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

責任編輯:武曉燕 來源: 養碼場
相關推薦

2011-12-13 14:44:41

51CTO

2017-06-29 11:11:17

2020-07-10 09:49:53

數據清理數據分析查找異常

2023-02-08 07:09:40

PythonChatGPT語言模型

2018-03-27 18:12:12

PythonHTML

2012-09-19 13:03:00

2019-10-22 08:42:59

AI 數據人工智能

2018-05-17 10:05:24

運行iPadPython

2019-11-28 09:23:17

Python機器學習數據庫

2020-05-09 10:38:31

Python透視表數據

2013-02-26 10:28:00

項目管理項目經理時間管理

2018-05-09 12:27:34

Linux命令尋找文件

2020-12-10 10:46:23

PythonExcel圖片

2018-12-06 08:40:43

PythonR函數編程語言

2020-09-25 08:40:02

Python開發網絡

2019-12-26 09:28:34

TCPPython通信

2021-03-04 13:40:57

Python文件代碼

2020-10-22 10:15:33

優化Windows電腦

2021-06-02 15:10:20

PythonScrapy視頻

2020-11-06 17:42:02

Python開發工具
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 天天看片天天干 | 免费视频一区二区 | 成人在线视频看看 | 五月天激情电影 | 亚洲精品在线观看网站 | 91高清在线观看 | 久久91精品| 欧美久久久久久久久 | 日日夜夜天天久久 | 亚洲人va欧美va人人爽 | www日| 久久99一区二区 | 成人性生交大片免费看r链接 | 国产精品久久久久久久午夜片 | 一区二区三区欧美大片 | 第一区在线观看免费国语入口 | 国产午夜精品一区二区三区四区 | 欧美性大战久久久久久久蜜臀 | 日韩成人在线视频 | 欧美国产激情二区三区 | 国产中文字幕在线 | 日本不卡视频 | 久久久www成人免费精品 | 午夜av免费 | 久久国产欧美日韩精品 | 欧美激情a∨在线视频播放 成人免费共享视频 | 日韩综合 | 久久蜜桃资源一区二区老牛 | 日韩在线一区二区三区 | 成人福利网站 | 理论片午午伦夜理片影院 | 91视频一88av| 久久久久久免费毛片精品 | 久久久久国产一区二区三区四区 | 成人精品啪啪欧美成 | 久久黄色网 | 亚洲精彩视频 | 九九热这里只有精品在线观看 | 欧美精品一区在线发布 | 免费看国产精品视频 | 黄网站在线播放 |