懵懂的菜鸟

Stay hungry,Stay foolish.

导航

2017年8月23日 #

python按行读取并替换

摘要: fp = open(''test2.txt','w') #打开你要写得文件test2.txt lines = open('test1.txt').readlines() #打开文件,读入每一行 for s in lines: fp.write( s.replace('love','hate').re 阅读全文

posted @ 2017-08-23 13:54 懵懂的菜鸟 阅读(7335) 评论(0) 推荐(0) 编辑

python 爬取网页内容

摘要: 1 #encoding:UTF-8 2 import urllib 3 import urllib.request 4 import bs4 5 from bs4 import BeautifulSoup as bs 6 def test1(): 7 url = "http://www.stylusstudio.com/edifact/D95B/CODECO.htm" 8... 阅读全文

posted @ 2017-08-23 11:35 懵懂的菜鸟 阅读(575) 评论(0) 推荐(0) 编辑

file.write(str),file.writelines(sequence)

摘要: file.write(str)的参数是一个字符串,就是你要写入文件的内容.file.writelines(sequence)的参数是序列,比如列表,它会迭代帮你写入文件。 阅读全文

posted @ 2017-08-23 11:18 懵懂的菜鸟 阅读(473) 评论(0) 推荐(0) 编辑