BeautifulSoup模块的简单使用详解编程语言
2023-06-13 09:20:24 时间
可以通过dir(BeautifulSoup.BeautifulSoup)查看其有什么函数,如果想知道某个函数的含义可以使用help(BeautifulSoup.BeautifulSoup.find)来查看其官方文档。
可以使用pprint来整输出,使用dir和help之前一定要import BeautifulSoup。
# -*- coding:utf8 -*- import urllib import urllib2 import BeautifulSoup import re htmlSource = urllib.urlopen("http://www.taobao.com/").read(200000) soup = BeautifulSoup.BeautifulSoup(htmlSource) #输出 head ... /head print soup.head #输出 title ... /title print soup.head.title #会返回一个列表,每个列表元素都是 a ... /a tags = soup.findAll(a) print tags print 京东放养的爬虫 #取 a /a 中间包含的元素,如果有href则输出 for item in soup.fetch(a,href=True): print item[href] #找到所有的 a /a ,如果其中href元素中含有taobao则输出 for a in soup.findAll(a,href=True): if re.findall(taobao, a[href]): print "Found the URL:", a[href] #输出 div /div 中间class属性等于J_Tanx mod,只输出第一个 print str(soup.find("div",{"class":"J_Tanx mod"}))
8393.html
cjava相关文章
- 基于STM32的嵌入式语音识别模块设计实现「建议收藏」
- python的re模块分组匹配
- BOSHIDA AC-DC电源模块的模块组合
- 【CSS】课程网站 网格商品展示 模块制作 ② ( 网格商品展示盒子模型测量及样式 | 处理列表间隙导致意外换行问题 | 代码示例 )
- WordPress 技巧:为评论模块增加更多 HTML 标签支持
- struts2:多模块多配置文件开发详解编程语言
- python多线程模块threading使用范例代码详解编程语言
- python collection模块中几种数据结构(Counter、OrderedDict、namedtup)详解编程语言
- Python常用的第三方模块——学习笔记详解编程语言
- Python 字符串操作及string模块使用详解编程语言
- 小白的Python之路 day5 模块XML特点和用法详解编程语言
- [javaEE] 三层架构案例-用户模块(二)详解编程语言
- python的memory_profiler模块使用详解编程语言
- Django的auth【认证】模块简介详解编程语言
- python模块之re模块详解编程语言
- 借助Redis实现多模块加载(多模块中redis)