今日写了个爬虫,爬取前程无忧的招聘信息
老套路,首先获取网页源代码
#-*- coding:utf-8 -*-
import requests
url = 'http://search.51job.com/jobsearch/search_result.php?'
page_req = requests.get(url)
page = page_req.text.encode('utf-8')
print page
结果,中文乱码:
浏览器查看,前程无忧源代码,是GBK编码,好吧,转GBK
非法字符,好吧,高级点,我转GB18030
尼玛,又是一种奇怪的字符,继续整,找网页帖子,大概是说先解码成GBK再转UTF_8 把 page = page_req.text.decode('gbk').encode('