11.18爬虫学习(BeautifulSoup类)
1、把html解析放到txt中
import requests
import os
r=requests.get('http://python123.io/ws/demo.html')
a=r.text
p2='e://guoli/'
if not os.path.exists(p2):
os.mkdir(p2)
with open(p2+'1.txt','w')as f:
f.write(a)
f.close()
from bs4 import BeautifulSoup
b=BeautifulSoup(open(p2+'1.txt'),'html.parser')
print(b.prettify())
with open(p2+'2.txt','w')as f2:
f2.write(b.prettify())
f2.close()