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

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

1、字符串+数字的情况

 

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


2、索引字符串

#显示内容:t
print 'test'[0]

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

3、选择字符串的子序列

#显示内容:est
print 'test'[1:]

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

#显示内容:tes
print 'test'[:3]

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


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

#显示内容:5
#find函数返回'for'所在位置号5
text = '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。



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值