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,练练手. 编码问题 因为涉及到中文,所以必然地涉及到了编码的问题,这一次借这个机会算是彻底搞清楚了. 问题要从文字的编码讲 ...
随机推荐
- WP runtime 获取cookie
HttpBaseProtocolFilter httpBaseProtocolFilter = new HttpBaseProtocolFilter(); HttpCookieManager http ...
- kafka 修改partition,删除topic,查询offset
修改分区个数: ./kafka-topics./kafka/<id_of_kafka> --alter --partitions 10 --topic test_topic 上面命令将te ...
- How to Pronounce OF
How to Pronounce OF Tagged With: OF Reduction Study the OF reduction. There are many reductions in ...
- (3)shiro自定义realm
上面一章说到shiro的认证和授权最底层就是调用realm的getAuthorizationInfo(获取用户的角色和资源)和getAuthenticationInfo(校验账号密码是否正确)两个方法 ...
- win10为什么不能把文件直接拖拽
- 向oracle中的表插入数据的方法
向oracle中的表插入数据的方法有以下几种: 假设表名为User 第一种方法:select t.*,rowid from User t;-->点击钥匙那个标记就可向表中添加数据 第二种方法:s ...
- maven配置国内镜像库
https://www.cnblogs.com/xiongxx/p/6057558.html
- sudoers的权限被改,又忘记了root密码,又不能重启。这么做。
报下面这个错 sudo: /etc/sudoers is world writablesudo: no valid sudoers sources found, quittingsudo: unabl ...
- 大型运输行业实战_day02_1_数据库设计与powerDesigner使用
1.安装powerDesigner 1. 傻瓜式的安装 2.在安装的过程中选择地区后才可以点击同意和下一步 3.安装地址,建议直接把c改为d 4.其他选项直接下一步 2.使用powerDesigner ...
- 可能空字符串转换为浮点型或者整数型:java.lang.NumberFormatException: For input string: " "
Integer.valueOf(str.equals("")?"0":str)