日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
如何用Python來找你喜歡的妹子?

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

創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比澠池網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式澠池網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋澠池地區(qū)。費(fèi)用合理售后完善,10年實(shí)體公司更值得信賴。

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

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

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

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

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

操作流程:

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

主要學(xué)習(xí)到的技術(shù):

  • 學(xué)習(xí)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.             query_data = {
  10.                 'page':page,
  11.                 'gender':self.gender,
  12.                 'starage':self.stargage,
  13.                 'endage':self.endgage,
  14.                 'stratheight':self.startheight,
  15.                 'endheight':self.endheight,
  16.                 'marry':self.marry,
  17.                 'salary':self.salary,
  18.             }
  19.             url = 'http://www.lovewzly.com/api/user/pc/list/search?'+urllib.urlencode(query_data)
  20.             print url
  21.             req = urllib2.Request(url, headers=headers)
  22.             response = urllib2.urlopen(req).read()
  23.             # print response
  24.             self.parse_data(response)
  25.             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.       for person in persons:
  8.           nick = person.get('username')
  9.           gender = person.get('gender')
  10.           age = 2018 - int(person.get('birthdayyear'))
  11.           address = person.get('city')
  12.           heart = person.get('monolog')
  13.           height = person.get('height')
  14.           img_url = person.get('avatar')
  15.           education = person.get('education')
  16.           print nick,age,height,address,heart,education
  17.           self.store_info(nick,age,height,address,heart,education,img_url)
  18.           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)心獨(dú)白
  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'{}歲_身高{}_學(xué)歷{}_{}_{}.jpg'.format(age,height,education, address, nick)
  14.         try:
  15.             # 補(bǔ)全文件目錄
  16.             image_path = u'E:/store/pic/{}'.format(tag)
  17.             # 判斷文件夾是否存在。
  18.             if not os.path.exists(image_path):
  19.                 os.makedirs(image_path)
  20.                 print image_path + ' 創(chuàng)建成功'
  21.             # 注意這里是寫入圖片,要用二進(jìn)制格式寫入。
  22.             with open(image_path + '/' + filename, 'wb') as f:
  23.                 f.write(urllib.urlopen(img_url).read())
  24.             txt_path = u'E:/store/txt'
  25.             txt_name = u'內(nèi)心獨(dú)白.txt'
  26.             # 判斷文件夾是否存在。
  27.             if not os.path.exists(txt_path):
  28.                 os.makedirs(txt_path)
  29.                 print txt_path + ' 創(chuàng)建成功'
  30.             # 寫入txt文本
  31.             with open(txt_path + '/' + txt_name, 'a') as f:
  32.                 f.write(heart)
  33.         except Exception as e:
  34.             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.        for j in range(len(person)):
  13.            self.sheetInfo.write(self.count, j, person[j])
  14.        self.f.save(u'我主良緣.xlsx')
  15.        self.count += 1
  16.        print '插入了{(lán)}條數(shù)據(jù)'.format(self.count)

***展現(xiàn)!

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


標(biāo)題名稱:如何用Python來找你喜歡的妹子?
URL分享:http://www.dlmjj.cn/article/dhipsgc.html