调试修改爬虫
This commit is contained in:
@@ -135,13 +135,24 @@
|
||||
|
||||
<!-- 爬虫解析结果 -->
|
||||
<el-table-column label="解析结果" width="220">
|
||||
<template #default="{ row }">
|
||||
<el-tag
|
||||
:type="getStatusTagType(row.itemExecuteStatus)"
|
||||
size="small"
|
||||
>
|
||||
{{ getAnalyzeStatus(row.itemExecuteStatus) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- 来源 -->
|
||||
<el-table-column label="来源" width="220">
|
||||
<template #default="{ row }">
|
||||
<div class="parse-result">
|
||||
<div v-if="row.category" class="result-item">
|
||||
<el-tag size="small" type="info">{{ row.category }}</el-tag>
|
||||
</div>
|
||||
<div v-if="row.source" class="result-item">
|
||||
来源: {{ row.source }}
|
||||
{{ row.source }}
|
||||
</div>
|
||||
<div v-if="row.tags" class="result-item">
|
||||
标签: {{ row.tags }}
|
||||
@@ -341,6 +352,7 @@
|
||||
<ArticleAdd
|
||||
v-if="convertDialogVisible"
|
||||
:initial-data="convertFormData"
|
||||
:collection-item-id="convertItem?.id"
|
||||
:show-back-button="false"
|
||||
@publish-success="handleConvertSuccess"
|
||||
@back="convertDialogVisible = false"
|
||||
@@ -501,7 +513,8 @@ function handleViewDetail(row: DataCollectionItem) {
|
||||
// ==================== 转换操作 ====================
|
||||
|
||||
/**
|
||||
* 处理富文本内容,清理不必要的样式
|
||||
* 处理富文本内容,清理可能导致冲突的样式
|
||||
* 采用温和策略:只移除明显有问题的样式,保留大部分原始格式
|
||||
*/
|
||||
function cleanHtmlContent(html: string): string {
|
||||
if (!html) return '';
|
||||
@@ -510,32 +523,61 @@ function cleanHtmlContent(html: string): string {
|
||||
const tempDiv = document.createElement('div');
|
||||
tempDiv.innerHTML = html;
|
||||
|
||||
// 移除所有内联样式中的字体大小、字体族等可能导致显示问题的样式
|
||||
// 需要移除的问题样式属性(这些通常会导致显示问题)
|
||||
const problematicStyles = [
|
||||
'font-family', // 字体族可能不存在
|
||||
'font-size', // 字体大小可能过大或过小
|
||||
'line-height', // 行高可能不适配
|
||||
'width', // 固定宽度可能导致布局问题
|
||||
'height', // 固定高度可能导致内容截断
|
||||
'max-width', // 最大宽度限制
|
||||
'max-height', // 最大高度限制
|
||||
'position', // 定位可能导致布局混乱
|
||||
'top', 'left', 'right', 'bottom', // 定位相关
|
||||
'z-index', // 层级可能冲突
|
||||
'float', // 浮动可能导致布局问题
|
||||
];
|
||||
|
||||
// 处理所有带有内联样式的元素
|
||||
const elementsWithStyle = tempDiv.querySelectorAll('[style]');
|
||||
elementsWithStyle.forEach((el) => {
|
||||
const element = el as HTMLElement;
|
||||
const style = element.style;
|
||||
|
||||
// 保留一些重要的样式,移除可能冲突的样式
|
||||
// 收集所有当前样式
|
||||
const preservedStyles: string[] = [];
|
||||
for (let i = 0; i < style.length; i++) {
|
||||
const property = style[i];
|
||||
const value = style.getPropertyValue(property);
|
||||
|
||||
// 保留文本颜色
|
||||
if (style.color) preservedStyles.push(`color: ${style.color}`);
|
||||
// 保留背景色
|
||||
if (style.backgroundColor) preservedStyles.push(`background-color: ${style.backgroundColor}`);
|
||||
// 保留文本对齐
|
||||
if (style.textAlign) preservedStyles.push(`text-align: ${style.textAlign}`);
|
||||
// 保留边距
|
||||
if (style.marginTop) preservedStyles.push(`margin-top: ${style.marginTop}`);
|
||||
if (style.marginBottom) preservedStyles.push(`margin-bottom: ${style.marginBottom}`);
|
||||
// 如果不在问题样式列表中,则保留
|
||||
if (!problematicStyles.includes(property) && value) {
|
||||
preservedStyles.push(`${property}: ${value}`);
|
||||
}
|
||||
}
|
||||
|
||||
element.setAttribute('style', preservedStyles.join('; '));
|
||||
// 重新设置样式
|
||||
if (preservedStyles.length > 0) {
|
||||
element.setAttribute('style', preservedStyles.join('; '));
|
||||
} else {
|
||||
element.removeAttribute('style');
|
||||
}
|
||||
});
|
||||
|
||||
// 移除可能的外部类名,避免样式冲突
|
||||
// 只移除明显的外部框架类名(如bootstrap、tailwind等)
|
||||
const problematicClassPrefixes = ['col-', 'row-', 'container', 'flex-', 'grid-', 'd-', 'p-', 'm-', 'w-', 'h-'];
|
||||
const elementsWithClass = tempDiv.querySelectorAll('[class]');
|
||||
elementsWithClass.forEach((el) => {
|
||||
el.removeAttribute('class');
|
||||
const classList = el.className.split(' ').filter(cls => {
|
||||
// 如果类名以问题前缀开头,则移除
|
||||
return !problematicClassPrefixes.some(prefix => cls.startsWith(prefix));
|
||||
});
|
||||
|
||||
if (classList.length > 0) {
|
||||
el.className = classList.join(' ');
|
||||
} else {
|
||||
el.removeAttribute('class');
|
||||
}
|
||||
});
|
||||
|
||||
return tempDiv.innerHTML;
|
||||
@@ -632,6 +674,14 @@ function getStatusText(status: number | undefined): string {
|
||||
}
|
||||
}
|
||||
|
||||
function getAnalyzeStatus(executeStatus: number | undefined): string {
|
||||
switch (executeStatus) {
|
||||
case 0: return '解析失败';
|
||||
case 1: return '解析成功';
|
||||
default: return '未知';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态标签类型
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user