Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中使用beautifulsoup包后保留标记中的文本_Python_Beautifulsoup - Fatal编程技术网

如何在python中使用beautifulsoup包后保留标记中的文本

如何在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(_))[

我有一个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(_))[-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