如何在python中使用beautifulsoup包后保留标记中的文本
我有一个html标签,如下所示如何在python中使用beautifulsoup包后保留标记中的文本,python,beautifulsoup,Python,Beautifulsoup,我有一个html标签,如下所示 摘录: a_tag['href'] 保存到文件: with open('output.txt', 'w') as f: f.write(a_tag['href']) 将其写入文件,如TXT或CSV。或者将其存储到数据库。提取: a_tag['href'] for _ in soup.find_all('a'): print _ text = re.split(r'">',re.split(r'="', str(_))[
摘录:
a_tag['href']
保存到文件:
with open('output.txt', 'w') as f:
f.write(a_tag['href'])
将其写入文件,如TXT或CSV。或者将其存储到数据库。提取:
a_tag['href']
for _ in soup.find_all('a'):
print _
text = re.split(r'">',re.split(r'="', str(_))[-1])[0]
print text
保存到文件:
with open('output.txt', 'w') as f:
f.write(a_tag['href'])
将其写入文件,如TXT或CSV。或者将其存储到数据库。是否保留?提取href或将其保存到文件?是否保留?提取href或将其保存到文件?
for _ in soup.find_all('a'):
print _
text = re.split(r'">',re.split(r'="', str(_))[-1])[0]
print text