响应。文本返回字节和怪异符号
我正在尝试刮擦网站 url ='https://spar.pl/gazetka/spar/'
, 并尝试使用控制台或VS代码:
requests.get(url).text
返回我未知的字节和其他符号。它如何开始的示例:
`\x139��HM�!�\x11:|�{R�����-z\x08~+�O\x00�\x14Ʌ<λ����dk4 \x00R�(�\x0bPɲ.Ģ��Eu��n���/_M�L�\x14�X�ܪt-������\x07�||��\x07��\x00��\x0c\x08:�i�T�ݿ\x7f?\x08�\'\x1c��I!�\x14\x03\x15R�\\�n\x15b\'���\x14�N���+�(��������\u05c9\x04HB\x08�hou\x0c�~/~�v���9ԯ?g��"�sZ\x13# ��j\r*�j)�K|�\x19NZ��s�\r��N�q����=x\x05�\x0b��2�0\x05���V�\x7f��������\x02�}���\x18Pl�aU����\'\x1d˷N�a`�\x0f���:���w&\x0b�\t��5���Y-fВ\x14\x10�?��\x17\x0f\r\x11�s��%n`
奇怪的是,当我在jupyter笔记本中尝试相同的代码时,我返回了普通文本,示例
'<!DOCTYPE html>\n<html lang="pl-PL">\n\n\t<head>\t\n\t\t<title>SPAR | SPAR – świeżość i wybór gwarantowane</title>\n\t\t\n\t\t<meta charset=\'UTF-8\'>\n\t\t<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=n
,还有一个几乎相同的https://spar.par.pal.ply.pl/gazetka/ EUROSPAR/
,这两种方法都返回干净的文本。
我已经尝试解码结果,或使用Response.content
,但我觉得它没有帮助。我真的很好奇为什么问题出现了,以及如何解决问题。
I'm trying to scrape a siteurl = 'https://spar.pl/gazetka/spar/'
,
and trying in either console or VS Code:
requests.get(url).text
returns a jumble of bytes and other symbols unknown to me. The example of how it starts:
`\x139��HM�!�\x11:|�{R�����-z\x08~+�O\x00�\x14Ʌ<λ����dk4 \x00R�(�\x0bPɲ.Ģ��Eu��n���/_M�L�\x14�X�ܪt-������\x07�||��\x07��\x00��\x0c\x08:�i�T�ݿ\x7f?\x08�\'\x1c��I!�\x14\x03\x15R�\\�n\x15b\'���\x14�N���+�(��������\u05c9\x04HB\x08�hou\x0c�~/~�v���9ԯ?g��"�sZ\x13# ��j\r*�j)�K|�\x19NZ��s�\r��N�q����=x\x05�\x0b��2�0\x05���V�\x7f��������\x02�}���\x18Pl�aU����\'\x1d˷N�a`�\x0f���:���w&\x0b�\t��5���Y-fВ\x14\x10�?��\x17\x0f\r\x11�s��%n`
Oddly enough, when I try the same code in Jupyter Notebook, I'm returned with normal text, example
'<!DOCTYPE html>\n<html lang="pl-PL">\n\n\t<head>\t\n\t\t<title>SPAR | SPAR – świeżość i wybór gwarantowane</title>\n\t\t\n\t\t<meta charset=\'UTF-8\'>\n\t\t<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=n
What's more, a site that's nearly identical https://spar.pl/gazetka/eurospar/
, both methods return clean text.
I've tried decoding the result, or using response.content
, but I couldn't find it helpful. I'm really curious why the problem occurs at all, and how to possibly solve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
try