解决方法:
正则提取出多个列表,然后利用 Pandas 的 DataFrame 数据类型写入 excel,具体格式你自己安排,这里给出个基本示例:
text = """1 产品 red 单价 价格 备注 2 产品 red 单价 价格 备注
import pandas as pd
import re
p = re.compile('>(\S+)')
q = p.findall(text)
table = pd.read_excel(r'D:\test.xlsx')
table['your title'] = pd.Series(q)
table.to_excel(r'D:\test.xlsx')
结果:
我一般使用BeautifulSoup,还是比较简单的
soup=BeaitifulSoup(html,'html.parser')
要找到某各元素使用find_all方法就行
for div in soup.find_all('div'):
但是经常会遇到网站有反爬的设置,比如子结点中含有换行符,只要写个函数去掉子结点间的换行符就行