Python Web抓取返回带有标记的输出-replacement.text

Python Web抓取返回带有标记的输出-replacement.text,python,beautifulsoup,Python,Beautifulsoup,我必须修改一个只返回标签的网页抓取项目,但现在我必须返回标签。通过使用标记调用它,或者使用insert_after或insert_before插入输出的后面和前面 代码如下: result = { 'url': url, 'title': '', 'description': '', 'h2': [],} for item in soup.find_all( ["h2&q

我必须修改一个只返回标签的网页抓取项目,但现在我必须返回标签。通过使用标记调用它,或者使用insert_after或insert_before插入输出的后面和前面 代码如下:

result = {
            'url': url,
            'title': '',
            'description': '',
            'h2': [],}
    
    
for item in soup.find_all( ["h2"]):
    text =( item.text)
    if (item.name == 'h2') and text!= None and text.strip() != '':
        result['h2'].append(text)
结果:“标题示例”/
需要生成输出:“tagshereExample of title/tagshere”

您是否检查了项目中的内容?appenditem而不是appendtext?或者你应该简单地做+文本+