ValueError: Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration.

Aperta
#142 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@AdrianAtZyte ci sta già lavorando.

Dal 27/9/2026.

  • #271 di @AdrianAtZyte — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
30/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
python
Ambito
web-dev

Direzione di ricerca

Start by tracing extruct.extract in extruct/_extruct.py into parse_xmldom_html in extruct/utils.py, then reproduce the failure with the URL and input shown in the report. Clarify the project's expected handling of lxml parsing errors before defining a regression test and the intended graceful behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

When scraping the URL: http://www.reakes.com/

Error:

Traceback (most recent call last):
  File ".../website_scraping.py", line 161, in getWebsiteScrapedDataForURL
    data = extruct.extract(r.text, base_url=base_url)
  File "/usr/local/lib/python3.8/site-packages/extruct/_extruct.py", line 58, in extract
    tree = parse_xmldom_html(htmlstring, encoding=encoding)
  File "/usr/local/lib/python3.8/site-packages/extruct/utils.py", line 16, in parse_xmldom_html
    return lxml.html.fromstring(html, parser=parser)
  File "/usr/local/lib/python3.8/site-packages/lxml/html/__init__.py", line 875, in fromstring
    doc = document_fromstring(html, parser=parser, base_url=base_url, **kw)
  File "/usr/local/lib/python3.8/site-packages/lxml/html/__init__.py", line 761, in document_fromstring
    value = etree.fromstring(html, parser, **kw)
  File "src/lxml/etree.pyx", line 3237, in lxml.etree.fromstring
  File "src/lxml/parser.pxi", line 1871, in lxml.etree._parseMemoryDocument
ValueError: Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration.

I would expect a scraper to fail gracefully and not let a problem with lxml propagate out, but not sure what the philosophy of extruct is specifically.

This might be helpful:
https://stackoverflow.com/questions/15830421/xml-unicode-strings-with-encoding-declaration-are-not-supported

Lingua principale
Python
Stelle
986
Fork
127
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di scrapinghub/extruct

Tutte le issue di scrapinghub/extruct

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.