鱼C论坛

 找回密码
 立即注册
查看: 2847|回复: 2

太久没玩了,请教一个登陆问题

[复制链接]
发表于 2021-6-12 11:06:04 | 显示全部楼层 |阅读模式
5鱼币
  1. #coding=utf-8

  2. import requests,re,os,time,pymysql,time
  3. from lxml import etree
  4. down_path = '新余快速人才网'
  5. if not os.path.exists(down_path):
  6.     os.makedirs(down_path)
  7. url3 = []
  8. def nextpage(lastpage):
  9.     for i in range (1,2):
  10.         print('页码:',i)
  11.         nexturl = f'https://www.xinyurc.com/index.php?m=&c=jobs&a=jobs_list&page={i}'
  12.         r = s.get(url=nexturl).text
  13.         html = etree.HTML(r)
  14.         href = html.xpath('/html/body/div[5]/div[1]/div[2]/div/div[3]/a/@href')  # 公司主页
  15.         global url3
  16.         url3.extend(href)
  17.     url3 = set(url3)
  18.     print(url3)
  19.     for h in url3:
  20.         print('hurl:',h)
  21.         time.sleep(1)
  22.         r = s.get(url=h).text


  23.         jobs = re.findall('<a href="(.*?)">全部职位',r)#全部职位
  24.         jobs = 'https://www.xinyurc.com' + jobs[0]#全部职位链接
  25.         r2 = s.get(url=jobs).text
  26.         print('jobs是:',jobs)
  27.         html2 = etree.HTML(r2)
  28.         #alljobs = html2.xpath('/html/body//div[@class="jname"]/a/text()')#全部职位
  29.         try:
  30.             allurl = html2.xpath('/html/body//div[@class="jname"]/a/@href')#全部职位URl
  31.         except:
  32.             pass

  33.         for url in allurl:  # 遍历全部职位url
  34.             r = s.get(url).text
  35.             print('Url:',url)
  36.             html = etree.HTML(r)
  37.             job = html.xpath('/html/body/div[3]/div/div/div[2]/div[1]/text()')[0]  # 岗位名称
  38.             cname = html.xpath('/html/body//div[@class="comname"]/a/text()')[0]  # 公司名称
  39.             jobin = html.xpath('/html/body/div[4]/div[1]/div[1]/div[1]/div[2]/text()')[0]  # 全职/兼职
  40.             joba = html.xpath('/html/body//div[@class="itemli"][2]/text()')  # 职位类别
  41.             if len(joba) == 0:
  42.                 joba = ['无']
  43.             jobnum = html.xpath('/html/body/div[4]/div[1]/div[1]/div[1]/div[4]/text()')[0]  # 招聘人数
  44.             #jobsc = html.xpath('/html/body/div[4]/div[1]/div[1]/div[1]/div[6]/text()')[0]  # 学历要求
  45.             #jobyear = html.xpath('/html/body/div[4]/div[1]/div[1]/div[1]/div[7]/text()')[0]  # 工作经验
  46.             sex = html.xpath('/html/body/div[4]/div[1]/div[1]/div[1]/div[8]/text()')[0]  # 性别要求
  47.             if sex == '不限':
  48.                 sex = 0
  49.             elif sex == '女':
  50.                 sex = 2
  51.             elif sex == '男':
  52.                 sex = 1
  53.             #old = html.xpath('/html/body/div[4]/div[1]/div[1]/div[1]/div[10]/text()')[0]  # 年龄要求
  54.             #intype = html.xpath('/html/body/div[4]/div[1]/div[1]/div[1]/div[11]/text()')[0]  # 招聘部门
  55.             jobaddress = html.xpath('/html/body/div[4]/div[1]/div[1]/div[1]/div[13]/text()')[0]  # 工作地点
  56.             #whos = html.xpath('/html/body/div[4]/div[1]/div[1]/div[2]/div[2]/text()[1]')[0]  # 联系人
  57.             andtel = html.xpath('/html/body/div[4]/div[1]/div[1]/div[2]/div[4]/span/text()')  # 联系电话
  58.             classjob = html.xpath('/html/body//div[@class="describe"]/div[@class="txt"]/text()')#职位描述
  59.             money = html.xpath('/html/body//div[@class="jobstit"]/div[@class="wage"]/text()')[0]#薪资

  60.             if '1K' in money:
  61.                 money = 2
  62.             elif '2K' in money:
  63.                 money = 3
  64.             elif '3K' in money:
  65.                 money = 4
  66.             elif '4K' in money:
  67.                 moeny = 5
  68.             elif '5K' in money:
  69.                 money = 6
  70.             elif '6K' in money:
  71.                 money = 6
  72.             elif '7K' in money:
  73.                 money = 6
  74.             elif '8K' in money or '9K' in money or '10K' in money or '11K' in money or '12K' in money:
  75.                 money = 7
  76.             elif '13K' in money or '14K' in money or '15K' in money or '16K' in money or '17K' in money or '18K' in money or '19K' in money or '20K' in money :
  77.                 money = 8
  78.             else:
  79.                 money = 0


  80.             if len(andtel) != 0:
  81.                 db = pymysql.connect(host = 'localhost' ,user='root', password='6330055', port=3306, db='spiders')
  82.                 cursor = db.cursor()

  83.                 data = {
  84.                 'uniacid' : 1,
  85.                 'uid' : 24,
  86.                 'isc' : 2,
  87.                 'cid' : 0,
  88.                 'title' : job,
  89.                 'jobcatindex' : 0,
  90.                 'salaryindex' : money,
  91.                 'flow' : 0,
  92.                 'recruitnum' : jobnum,
  93.                 'sexindex' : sex,
  94.                 'degreesindex' : 0,
  95.                 'experiencesindex' : 0,
  96.                 'des' : classjob,
  97.                 'chosewelfare' : ' a:1:{i:0;s:12:"其他补助";}',
  98.                 'imgs' : 'a:1:{i:0;s:0:"";}',
  99.                 'time':int(time.time()),
  100.                 'status' : 1,
  101.                 'istop' : 0,
  102.                 'toptime' : 'NULL',
  103.                 'flow' : 0,
  104.                 'istou' : 0,
  105.                 'isting' : 0,
  106.                 'citycode' : '360500',
  107.                 'telnum' : andtel[0],
  108.                 'address' : jobaddress,
  109.                 'state' : '1'
  110.                 }

  111.                 table = 'ims_lshd_zhaopinhign_zpxx'
  112.                 keys = ','.join(data.keys())
  113.                 values = ','.join(['%s'] * len(data))
  114.                 sql = 'INSERT INTO {table}({keys}) VALUES ({values})'.format(table=table,keys=keys,values=values)
  115.                 try:
  116.                     if cursor.execute(sql,tuple(data.values())):
  117.                         print('Successful')
  118.                         db.commit()
  119.                 except:
  120.                     print('Failed')
  121.                     db.rollback()
  122.                 db.close()

  123.             #     with open(f'{down_path}/新余快速人才网数据222222.txt', 'a') as f:
  124.             #         f.write(cname)
  125.             #         f.write(' ')
  126.             #         f.write('\n\n')
  127.             #         f.write('岗位名称:' + job)
  128.             #         f.write(' ')
  129.             #         f.write('职位类别:' + joba[0])
  130.             #         f.write(' ')
  131.             #         f.write('招聘人数:' + jobnum)
  132.             #         f.write(' ')
  133.             #         f.write('性别要求' + sex)
  134.             #         f.write(' ')
  135.             #         f.write(jobaddress)
  136.             #         f.write(' ')
  137.             #         f.write('联系电话' + andtel[0])
  138.             #         f.write('\n\n')
  139.             #         f.write('岗位职责:' + classjob)
  140.             #         f.write('\r\n\n')
  141.             #
  142.             #
  143.             # else:
  144.             #     pass











  145. if __name__ == '__main__':

  146.     url = 'https://www.xinyurc.com/index.php?m=Home&c=Members&a=login'
  147.     url2 = 'https://www.xinyurc.com/index.php?m=Home&c=jobs&a=jobs_list'
  148.     headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36',
  149.     'X-Requested-With': 'XMLHttpRequest',
  150.     'Sec-Fetch-Site': 'same-origin',
  151.     'Origin': 'https: // www.xinyurc.com',
  152.     'Referer': 'https://www.xinyurc.com/members/login',
  153.     'Accept-Encoding': 'gzip, deflate, br',
  154.     'sec-ch-ua-mobile': '?0',
  155.     'Sec-Fetch-Dest': 'empty',
  156.     'Sec-Fetch-Mode': 'cors',
  157.     'Sec-Fetch-Site': 'same-origin',
  158.     'sec-ch-ua': '" Not;A Brand";v = "99", "Google Chrome";v = "91", "Chromium";v = "91"',
  159.     'Host': 'www.xinyurc.com',
  160.     'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
  161.      'Content-Length': '46',
  162.      'Connection': 'keep-alive',
  163.      'Accept-Language': 'zh-CN, zh;q=0.9, en;q=0.8, zh-TW;q=0.7',
  164.      'Accept': 'application/json,text/javascript, */*; q=0.01',
  165.      'Date': 'Sat, 12 Jun 2021 02:34: 55 GMT',
  166.      'Expires': 'Thu, 19 Nov 1981 08: 52:00 GMT',
  167.     'Transfer-Encoding': 'chunked',
  168.     'Vary': 'Accept-Encoding',
  169.                }
  170.     data = {
  171.     'username': '15579001118',
  172.     'password':'6330055',
  173.     'expire': '1'
  174.     }
  175.     s = requests.session()
  176.     s.headers.update()
  177.     r = s.post(url=url,data=data,headers=headers,allow_redirects = True);

  178.     r = s.get(url=url2).text
  179.     print(r,'*****' * 10)
  180.     html = etree.HTML(r)

  181.     lastpage = html.xpath('/html/body/div[5]/div[1]/div[2]/div[17]/a[7]/@href')[0]
  182.     lastpage = re.findall('page=(\d{3})', lastpage)[0]
  183.     nextpage(lastpage)

复制代码



这里研究了蛮久,不知道为什么现在好像登陆不成功了

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-6-12 11:15:38 From FishC Mobile | 显示全部楼层
盘子开的太大,应先研究能否成功登录
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-6-12 13:32:53 | 显示全部楼层
加个登陆后的cookie试试
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-22 22:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表