# coding: utf-8
__author__ = 'zhangcx'
from urllib3 import PoolManager
import codecs
import json

class myjob(object):
    def __init__(self):
        self._page = 1
        self._totalPageCount = 0
        self._first = True
        self._hasNextPage = True
        self._http =  PoolManager()

    def getjob(self):
        if(self._hasNextPage):
                r = self._http.request('POST','http://www.lagou.com/jobs/positionAjax.json?px=default&city=%E6%AD%A6%E6%B1%89'
                                       ,{'first':'%s' % self._first,'pn':'%d' % self._page,'kd':'Java'})
                items = json.loads( r.data.decode('utf-8'))
                for item in items['content']['result']:
                    print("{name},{positionName},{salary}".format(name=item['companyShortName'],positionName = item['positionName'],salary=item['salary']))
                #print(items)
                self._hasNextPage = items['content']['hasNextPage']
                self._totalPageCount = items['content']['totalPageCount']

                if(self._page > 0):
                    self._first = 'false'
                if((self._page+ 1) > self._totalPageCount):
                    self._hasNextPage = False
                self._page += 1
                self.getjob()


if __name__ == "__main__":
    job = myjob()
    job.getjob()


Python小爬虫练习

 

相关文章:

  • 2021-06-10
  • 2022-12-23
  • 2022-02-05
  • 2021-11-09
  • 2022-02-12
  • 2021-08-10
  • 2021-12-30
猜你喜欢
  • 2022-12-23
  • 2021-04-01
  • 2021-09-06
  • 2022-01-10
  • 2021-10-19
  • 2021-04-16
相关资源
相似解决方案