44519

what have we learnt in day five

<h1 id="what-is-file">what is file?

virtual unit offered by operation system

<h1 id="steps-to-open-file">steps to open file

1.find the file_path(file_path)

2.open file(open)

3.read or change the file(read/write)

4.save the files(flush)

5.close the file (close)

<h1 id="three-modes-to-open-.txt-file">three modes to open .txt file

w:clear the file and write in

r:can only read

a:write in after the file

<h1 id="two-ways-to-open-.txt-file">two ways to open .txt file

b:binary

t:text

you'd better not to use three ways below

1.r+

2.a+

3.w+

<h1 id="with-in-charge-of-the-context">with in charge of the context

f=open() f.read() #close file automaticly with open() as f f.read() <h1 id="principle-of-crawler">principle of crawler

send requests through explore to get files,through requests module analog browser gets content

<h1 id="process-of-crawler">process of crawler

1.send requests(filling url)

2.get context

3.choose the value you need

<h1 id="use-of-requests-module">use of requests module

import requests res=requests.get(url) #wenben res.txt #erjinzhiliu res.content <h1 id="re-module">re module

re.S search all

re.findall() choose what you need in the context

if you need anything just(.*?)

来源:博客园

作者:tusier

链接:https://www.cnblogs.com/jimGraymane/p/11425882.html

Recommend