openpyxl.utils.exceptions.IllegalCharacterError где исправить - PullRequest
0 голосов
/ 29 мая 2020
import requests
import html2text
import openpyxl

with open('crawlingweb.csv')as f:
    content=f.readlines()
    content=[x.strip()for x in content]

excel_file=openpyxl.Workbook()
excel_sheet=excel_file.active

for i in range(100):
    url=content[i]
    req=requests.get(url)
    html=req.text
    raw=html2text.html2text(html)
    excel_sheet.append([raw])

excel_file.save('crawling.xlsx')
excel_file.close()

Я получил ошибку openpyxl.utils.exceptions.IllegalCharacterError и результаты сканирования не полностью отражают содержимое сайта. Если я не удовлетворен результатами сканирования, есть ли другой способ? спасибо

1 Ответ

0 голосов
/ 29 мая 2020
import requests
import html2text
import openpyxl
import re
from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE

with open('crawlingweb.csv')as f:
    content=f.readlines()
    content=[x.strip()for x in content]

excel_file=openpyxl.Workbook()
excel_sheet=excel_file.active

for i in range(50):
    url=content[i]
    req=requests.get(url)
    html=req.text
    raw=html2text.html2text(html)
    raw = ILLEGAL_CHARACTERS_RE.sub(r'', raw)
    excel_sheet.append([raw])

excel_file.save('crawling.xlsx')
excel_file.close()
...