python 爬虫 使用正则爬取51job内容并存入txt

python爬虫基础–使用正则提取51job内容输出到txt

from urllib import request
#url
url = 'https://search.51job.com/list/020000%252C010000%252C080200%252C070200%252C120300,000000,0000,00,9,99,%25E4%25BA%25BA%25E5%25B7%25A5%25E6%2599%25BA%25E8%2583%25BD,2,1.html?lang=c&stype=1&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=4&dibiaoid=0&address=&line=&specialarea=00&from=&welfare='
#变为请求
r=request.Request(url)
#访问得到结果
res = request.urlopen(r)
#读取并且解码
#print(res.read().decode('gbk'))#unicode解码方式

#读取网页编码格式
import chardet
html=res.read()
# code=chardet.detect(html)['encoding']
# print(code)
html=html.decode('gbk')
# print(html)
#提取
import re
#你需要留下的用(.*?),它的前后一定要有一个原来的存在内容,被你删掉的,用.*?表示
reg = re.compile('

你可能感兴趣的:(1010)