Home > other >  I want to put the CONTENT CONTENT output into a TXT, how should change
I want to put the CONTENT CONTENT output into a TXT, how should change

Time:04-26




To check the content and output a fj2. TXT, HTML code is as follows


The import requests
The import bs4
# import module
Def open_url (url) :
# define open_url function to get the parameter specifies the head
Headers={the user-agent: "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36}
"Res=requests. Get (url, headers=headers)
# get content
Return res


Def find_date (res) :
Soup=bs4. BeautifulSoup (res) text, ". The HTML parser ")
# page generated 16 object
The content=soup. The find (id="Cnt" - the Main - the Article - QQ)
# print (content)


Def the main () :
# define mainl function to call
Url="https://news.house.qq.com/a/20170702/003985.htm"
# specified page
Res=open_url (url)
# access to web resources
Find_date (res)


With the open (" fj2. TXT ", "w", encoding="utf-8") as file:
# generated file named fj, format for utf-8, text file
File. The write (res) text)
# to write the text content


If __name__=="__main__" :
The main ()


Novice small white, consult, best detail
  • Related