python爬虫作业

本文详细介绍了使用Python进行网络爬虫的实践过程,包括数据抓取、解析及存储等关键步骤。通过实例解析爬虫作业,帮助读者掌握Python爬虫的基本技巧和常见问题解决策略。
摘要由CSDN通过智能技术生成
import urllib.request
import ssl
import re
import xlwt
import xlrd
from xlutils.copy import copy
import DBUtils
def getContent(k,l):
    headers={
   
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" ,
    'Connection': 'keep-alive'
    }
    url = "https://search.51job.com/list/080700,000000,0000,00,9,99,%s,2,%s.html?lang=c&postchannel=0000&workyear=99&cotype=99&degreefrom=99&jobterm=99&companysize=99&ord_field=0&dibiaoid=0&line=&welfare="%(k,l)
    ##请求对象(url+请求头)
    req = urllib.request.Request(url,headers = headers)
    ##获取页面内容
    page = urllib.request.urlopen(req).read()

    page = page.decode("GBK")
    return page

# print(getContent())

def getItem(content):
    pattern = re.compile(
    r'"job_href":"(.+?)","job_name":"(.+?)".+?"company_href":"(.+?)","company_name":"(.+?)","providesalary_text":"(.*?)".+?"workarea_text":"(.*?)","updatedate":"(.*?)".*?"companytype_text":"(.*?)","degreefrom":"(.*?)".*?"attribute_text":(.*?),"companysize_text":"(.*?)","companyind_text":"(.*?)".*?')
    res = re.findall(pattern,content)
    return res;
#
# content = getContent()
# print(getItem(content))

def saveExcel():
    wb = xlwt.Workbook()
    sheet = wb.add_sheet("数据分析50")
    header 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值