python 爬取网页内容
#encoding:UTF-8
import urllib
import urllib.request
import bs4
from bs4 import BeautifulSoup as bs
def test1():
url = "http://www.stylusstudio.com/edifact/D95B/CODECO.htm"
resp = urllib.request.urlopen(url)
data = resp.read().decode('UTF-8')
soup = bs(data, 'html.parser')
segment11= soup.find_all('table')
segment1=segment11[7].find_all('tr')#表示第几个table,此时表示进去html网页中的第7个table f2=open('./text1.txt','a',encoding='cp852')
for item in segment1: print(item)
'''
<tr class="FrameTreeFont"><td><span class="FrameDrawFont">│
<span class="FrameHideFont">─</span>│<span class="FrameHideFont">─</span>├─</span>
<a class="FrameItemFont" href="DAM_.htm" target="classFrame" title="Damage">DAM</a>
Damage</td><td align="right"><span class="FrameDetailFont"> ×1
</span></td><td><span class="FrameDetailFont">(M)</span></td></tr>
''' print(item.get_text())#以文本方式呈现
'''
│─│─├─DAM Damage ×1 (M)
'''
# print(item.td.span.get_text())#获取具体标签内部内容
print([text for text in item.stripped_strings] )#以列表方式呈现
'''
['│', '─', '│', '─', '├─', 'DAM', 'Damage', '×1', '(M)']
'''
'''
soup.get_text("|")#u'\nI linked to |example.com|\n'进一步,通过strip去除掉文本每个位的头尾空白。 soup.get_text("|", strip=True)#u'I linked to|example.com'
'''
f2.writelines(str([text for text in item.stripped_strings])+'\n')
f2.close()
if __name__=='__main__':
test1()
python 爬取网页内容的更多相关文章
- python爬取网页内容demo
#html文本提取 from bs4 import BeautifulSoup html_sample = '\ <html> \ <body> \ <h1 id = & ...
- 利用python爬取海量疾病名称百度搜索词条目数的爬虫实现
实验原因: 目前有一个医疗百科检索项目,该项目中对关键词进行检索后,返回的结果很多,可惜结果的排序很不好,影响用户体验.简单来说,搜索出来的所有符合疾病中,有可能是最不常见的疾病是排在第一个的,而最有 ...
- python爬取豆瓣首页热门栏目详细流程
记录一下爬取豆瓣热门专栏的经过,通过这篇文章,你能学会requests,HTMLParser,json的基本使用,以及爬取网页内容的基本思路. 使用模块 1,获取豆瓣首页代码:首先我们需要访问豆瓣页面 ...
- Python爬取网页信息
Python爬取网页信息的步骤 以爬取英文名字网站(https://nameberry.com/)中每个名字的评论内容,包括英文名,用户名,评论的时间和评论的内容为例. 1.确认网址 在浏览器中输入初 ...
- python 爬取网页内的代理服务器列表(需调整优化)
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2017-08-30 20:38:23 # @Author : EnderZhou (z ...
- 第14.1节 通过Python爬取网页的学习步骤
如果要从一个互联网前端开发的小白,学习爬虫开发,结合自己的经验老猿认为爬虫学习之路应该是这样的: 一. 了解HTML语言及css知识 这方面的知识请大家通过w3school 去学习,老猿对于html总 ...
- 毕设之Python爬取天气数据及可视化分析
写在前面的一些P话:(https://jq.qq.com/?_wv=1027&k=RFkfeU8j) 天气预报我们每天都会关注,我们可以根据未来的天气增减衣物.安排出行,每天的气温.风速风向. ...
- Python 爬取所有51VOA网站的Learn a words文本及mp3音频
Python 爬取所有51VOA网站的Learn a words文本及mp3音频 #!/usr/bin/env python # -*- coding: utf-8 -*- #Python 爬取所有5 ...
- python爬取网站数据
开学前接了一个任务,内容是从网上爬取特定属性的数据.正好之前学了python,练练手. 编码问题 因为涉及到中文,所以必然地涉及到了编码的问题,这一次借这个机会算是彻底搞清楚了. 问题要从文字的编码讲 ...
随机推荐
- mongodb基础学习10-手动预分片
手动预分片是提前对分片创建一定数量足够使用的chunk,这样避免了IO上的压力 先对要演示的表进行分片 调用splitAt函数进行手动预分片,第一个参数指定要预分片的表,第二个参数指定分片规则,即当u ...
- Hive 和 HBase区别
作者:yuan daisy 链接:https://www.zhihu.com/question/21677041/answer/78289309 来源:知乎 著作权归作者所有.商业转载请联系作者获得授 ...
- DataType 数据类型
基本类型:四类八种:数值 : 整数:byte,short,int,long.默认是 int 小数:float,double 默认是 double 布尔:boolean ...
- 梯度下降法】三:学习率衰减因子(decay)的原理与Python
http://www.41443.com/HTML/Python/20161027/512492.html
- 获取RequestMapping注解中的属性
参考:https://www.cnblogs.com/2013jiutian/p/7294053.html @RequestMapping("/value1") @Controll ...
- JPA报错, PersistenceException_Unable to build Hibernate SessionFactory
javax.persistence.PersistenceException: [PersistenceUnit: TestJPA] Unable to build Hibernate Session ...
- oracle中的分支与循环语句
分支语句 if的三种写法一, if 2 < 1 then dbms_output.put_line('条件成立'); end if; 二, if 2 < 1 then dbms_outpu ...
- Dungeon Game (GRAPH - DP)
QUESTION The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a ...
- ios 打tag
修改spec文件的version: git commit -am"version 0.1.1" git push origin master -u git tag 0.1.1 gi ...
- Spring的2.5版本中提供了一种:p名称空间的注入(了解)
1. 步骤一:需要先引入 p 名称空间 * 在schema的名称空间中加入该行:xmlns:p="http://www.springframework.org/schema/p"( ...