《Python爬虫程序(工作职位类爬虫).pdf》由会员分享,可在线阅读,更多相关《Python爬虫程序(工作职位类爬虫).pdf(2页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Python 爬虫程序(工作职位类爬虫)import requests from lxml import etree import pymysql a=1 for num in range(1,25):url=https:/ name=html.xpath(/pclass=t1/span/a/title)#公司名 g_name=html.xpath(/spanclass=t2/a/title)#工作地点 dd=html.xpath(/divclass=el/spanclass=t3/text()#薪资 xz1=html.xpath(/divclass=el/spanclass=t4)xz=fo
2、r i in xz1:xz.append(i.xpath(string(.)#string(.)获取空值#发布时间 time=html.xpath(/divclass=el/spanclass=t5/text()#print(len(dd)#合并 list1=for n in range(50):try:list1.append(namen,g_namen,ddn,xzn,timen)except:continue conn=pymysql.connect(host=localhost,user=root,passwd=weirensheng666,db=pysql,charset=utf8)cursor=conn.cursor()sql=insert into 51job values(%s,%s,%s,%s,%s)cursor.executemany(sql,list1)mit()cursor.close()conn.close()print(获取第%d 页成功%a)a+=1