python re.findall 模块返回空列表

混凝土瞬间移动工程师 2019-01-11 08:07:11
今天用python爬取前程无忧的招聘信息,最后用正则表达式匹配的时候返回的是空列表,求大佬解答
import re
from urllib import request
def get_content(page):
url="https://search.51job.com/list/000000,000000,0000,00,9,99,%25E5%25A4%25A7%25E6%2595%25B0%25E6%258D%25AE,2,"+str(page)+".html"
rsp=request.urlopen(url)
html=rsp.read()
html=html.decode('gbk')
#print(html)
return html
def get(html):
reg = re.compile(r'class="t1">.*?<a target="_blank" title="(.*?)"href="(.*?)".*?<span class="t2"><a target="_blank" title="(.*?)".*?<span class="t3">(.*?)</span>.*?<span class="t4">(.*?)</span>.*?<span class="t5">(.*?)</span>',re.S) # 匹配换行符
items=re.findall(reg,html)
print(items)
return items
...全文
1121 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
xdn1ce 2019-01-12
  • 打赏
  • 举报
回复
大体可能有两点:1.urlopen的时候 需要一个headers参数
2.html.decode('utf-8')

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧