python处理html文档
"""
html文本处理
parsel
cssselect
"""
"""
文本 abc.txt
hello,1只爬虫
hello,2只爬虫
hello,3只爬虫
hello,4只爬虫
"""
from bs4 import BeautifulSoup
with open("D:/pachong/abc.txt","r") as f:
html=f.read()
print(html)
soup=BeautifulSoup(html,"lxml")
result=soup.find_all('div',class_='store')#find找一个,find_all找多个,找全部
print("===========")
if result is not None:
print(result)#1个列表
for i in result:#访问列表里面每隔元素
print(i.get_text())
#print(result.get_text())#找到class为store的div,输出这个div里面的文本
D:\pachong>html1.py
hello,1只爬虫
hello,2只爬虫
hello,3只爬虫
hello,4只爬虫
===========
[
hello,1只爬虫
,
hello,2只爬虫
,
hello,3只爬虫
,
hello,4只爬虫
]
hello,1只爬虫
hello,2只爬虫
hello,3只爬虫
hello,4只爬虫