django实战篇二
来源:互联网 发布:linux公社 编辑:程序博客网 时间:2024/06/05 14:53
今天在django的框架下重新运用可beautifulsoup,总结了一点语法
实例一个beautifulsoup对象
soup = bs4.BeautifulSoup(html)
它的字标签一样具有相关方法
我最多用的就是find_all(),它返回的是一个list,list中每个元素都具有相关特性
find_all('ul',attrs={'id':'business_listbox'}),find_all('strong', class_='productntitle')
find_all('a',href=re.compile("search.php\?CataID=&act=txt&tp=store&skey="))
获取某个标签的属性 a['href']
然后写成一个数组用list.append
最后写成字典格式,并以json返回
new_dict=dict.fromkeys(('name','href'))
new_dict['name']=all_name
new_dict['href']=href
back=json.dumps(new_dict,ensure_ascii=False)
return HttpResponse(back)
"My name is %s and weight is %d kg!" % ('Zara', 21)
实例一个beautifulsoup对象
soup = bs4.BeautifulSoup(html)
它的字标签一样具有相关方法
我最多用的就是find_all(),它返回的是一个list,list中每个元素都具有相关特性
find_all('ul',attrs={'id':'business_listbox'}),find_all('strong', class_='productntitle')
find_all('a',href=re.compile("search.php\?CataID=&act=txt&tp=store&skey="))
获取某个标签的属性 a['href']
然后写成一个数组用list.append
最后写成字典格式,并以json返回
new_dict=dict.fromkeys(('name','href'))
new_dict['name']=all_name
new_dict['href']=href
back=json.dumps(new_dict,ensure_ascii=False)
return HttpResponse(back)
"My name is %s and weight is %d kg!" % ('Zara', 21)
阅读全文
0 0
- django实战篇二
- django实战篇一
- django实战
- django实战(二)一个较完整的博客系统
- [Django实战] 第1篇 - 概述
- [Django实战] 第7篇 - Admin管理工具
- [Django实战] 第8篇 - 分页列表
- JUnit实战篇 (二)
- Ant实战篇 (二)
- Bugreport实战篇(二)
- Django(二)
- Django(二)
- Django(二)
- django 实战例子
- Django在OS X下的编程实战(二)操作博客数据模型
- 多线程编程 实战篇 (二)
- 多线程编程 实战篇 (二)
- [Django实战] 第2篇 - 关于MTV模式
- Bootstrap模态框--------传入参数
- ngx_http_slice_module分析
- django实战篇一
- 认识try(){}
- tween max 下载
- django实战篇二
- verticalseekbar在5.0以上系统时无法进入onProgressChanged,如何解决
- GOLANG sync.Once
- Nmap网络嗅探
- springboot静态资源css,js,img
- springmvc中修改request的参数以及实现去空格功能
- Could not find method runProguard问题解决
- 20.Valid Parentheses
- jpgraph安装使用