计算机导论学习第一课笔记

来源:互联网 发布:软件研发流程 编辑:程序博客网 时间:2024/06/06 01:09

第一部分、字符串学习(使用PYTHON)

1、字符串+数字的情况

 

print 'apple'+'!'*3
显示内容:apple!!!


2、索引字符串

#显示内容:tprint 'test'[0]#显示内容:末尾的‘t’print 'test'[-1]

3、选择字符串的子序列

#显示内容:estprint 'test'[1:]#不显示任何内容print 'test'[1:1]#显示内容:tesprint 'test'[:3]

#显示内容:test,与print 'test'结果相同print 'test'[:]


4、查找字符串中的字符串

#显示内容:5#find函数返回'for'所在位置号5text = 'test for you'print text.find('for')#显示内容:14(第二个“for”所在位置号)text2 = 'test for you, for me and for us!'print text2.find('for',6)

第二部分、网页的简单抓取

1、网页超链接的特征

<a href="http://XXX.XXXX.....">


2、利用字符串的知识从网页<a href="">标签中提取超链接信息

page =('<div id="top_bin"><div id="top_content" class="width60">''<div class="float-left"><a href="http://test.com">')start_link = page.find('<a href=')start_quote = page.find('"',start_link)end_quote = page.find('"',start_quote + 1)url = page[start_quote+1:end_quote]print url
显示url内容为:http://test.com。



原创粉丝点击