[Python] Scrapling Save PDF File Locally

Discussão em 'Python' iniciado por Stack, Maio 11, 2025.

  1. Stack

    Stack Membro Participativo

    I have to scrape a website which returns a static PDF file. The only Python package that can access the document successfully is scrapling. However, the PDF file returned is not saved correctly in my program at the moment. How can I get the program to successfully save the file with the provided format locally? Thanks for any help in advance!

    Code:

    from scrapling.fetchers import Fetcher

    url = 'https://www.website.com/document'
    page = Fetcher.get(url, stealthy_headers=True, follow_redirects=True)

    print(page.body)

    with open('file.pdf', 'wb') as f:
    f.write(page.body)


    PDF Output:

    ���$���%�����:dD���(����
    k���5(� c����ԡ�o��HEw��J�Q6y�����A�C�����*Aϯ��߶�E��9��eO7��DS�Y��M\�Pm$�]��I��Q�-g�)�/�|U���a�aA^��Ť��~]��ckG��w�y���E���
    ���i+���k�����l�\un�<@?��1��UTv =g��pE�ߥ��)���E�z�� t�-;�"5gE����ɹe��������H��j����^�Wf+d?qj���T�; ��-��6f_�ھ�5{N��c��cfT��-ol�՜c�����}�c���{�\Mr�ӏ�[�|kt���qu�/g��ѽ�6R������=�F�v}M1���������d~yc ��?�� ����X���I��lxff�#�`*�la����,I�,�h�m0���#�N?\�a�������xh��ٖ`��C���J�n��:��4ų���~I��I��:%b����9_Ѷ5cxK��ј��ӣAA��O�%�
    �~t������������=��1m��̟T�<�7�`�u�?oBÉ�j ����O��
    endstream
    endobj
    167 0 obj
    [ 250]
    endobj
    168 0 obj
    <>
    stream
    <?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?><x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="3.1-701"><rdf:rdf xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/"><pdf:producer>Microsoft® Word for Microsoft 365</pdf:producer></rdf:description><rdf:description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:title><rdf:alt><rdf:li xml:lang="x-default">CITY OF DANA POINT</rdf:li></rdf:alt></dc:title><dc:creator><rdf:seq><rdf:li>djacobo</rdf:li></rdf:seq></dc:creator></rdf:description><rdf:description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/"><xmp:creatortool>Microsoft® Word for Microsoft 365</xmp:creatortool><xmp:createdate>2025-04-24T10:23:49-07:00</xmp:createdate><xmp:modifydate>2025-04-24T10:23:49-07:00</xmp:modifydate></rdf:description><rdf:description rdf:about="" xmlns:xmpmm="http://ns.adobe.com/xap/1.0/mm/"><xmpmm:documentid>uuid:BAA60942-B4F0-4788-A464-1458F7144A4B</xmpmm:documentid><xmpmm:instanceid>uuid:BAA60942-B4F0-4788-A464-1458F7144A4B</xmpmm:instanceid></rdf:description>




















    </rdf:rdf></x:xmpmeta><?xpacket end="w"?>
    endstream
    endobj
    169 0 obj
    &lt;&gt;
    endobj
    170 0 obj
    &lt;&lt;4209A6BAF0B48847A4641458F7144A4B&gt;] /Filter/FlateDecode/Length 418&gt;&gt;
    stream
    ��p�9O�Qg�pE���"���S$��7���Y�㽘��Q1��X���R��I��I�&amp;A!̉�T����/v-A,���=YFt�[�N8��k��|&lt;ά`��p��� " � NC�!��N�B��D8I�?��d@
    5�j��#xO�)��3��������^B���� �nB!܂�Pw�J���=(�r��J���P
    m�ڡ��޾M�Ol�-���;_�X9��Y��w��#������\��pi}
    endstream
    endobj
    xref
    0 171
    0000000044 65535 f
    0000000017 00000 n
    0000000165 00000 n
    0000000235 00000 n
    0000000589 00000 n
    0000004581 00000 n
    0000004743 00000 n
    0000004969 00000 n
    0000005022 00000 n
    0000005075 00000 n
    0000005243 00000 n
    0000005475 00000 n
    0000005646 00000 n
    0000005882 00000 n
    0000006088 00000 n
    0000006294 00000 n
    0000006420 00000 n
    0000006450 00000 n
    0000006604 00000 n
    0000006678 00000 n
    0000006923 00000 n
    0000007108 00000 n
    0000007375 00000 n
    0000050824 00000 n
    0000052768 00000 n
    0000053132 00000 n
    0000057123 00000 n
    0000057329 00000 n
    0000057535 00000 n
    0000057741 00000 n
    0000057947 00000 n
    0000058153 00000 n
    0000058359 00000 n
    0000058537 00000 n
    0000058779 00000 n
    0000058910 00000 n
    0000058940 00000 n
    0000059099 00000 n
    0000059173 00000 n
    0000059423 00000 n
    0000059588 00000 n
    0000059901 00000 n
    0000063233 00000 n
    0000071533 00000 n
    0000000045 65535 f
    0000000046 65535 f
    0000000047 65535 f
    0000000048 65535 f
    0000000049 65535 f
    0000000050 65535 f
    0000000051 65535 f
    0000000052 65535 f
    0000000053 65535 f
    0000000054 65535 f
    0000000055 65535 f
    0000000056 65535 f
    0000000057 65535 f
    0000000058 65535 f
    0000000059 65535 f
    0000000060 65535 f
    0000000061 65535 f
    0000000062 65535 f
    0000000063 65535 f
    0000000064 65535 f
    0000000065 65535 f
    0000000066 65535 f
    0000000067 65535 f
    0000000068 65535 f
    0000000069 65535 f
    0000000070 65535 f
    0000000071 65535 f
    0000000072 65535 f
    0000000073 65535 f
    0000000074 65535 f
    0000000075 65535 f
    0000000076 65535 f
    0000000077 65535 f
    0000000078 65535 f
    0000000079 65535 f
    0000000080 65535 f
    0000000081 65535 f
    0000000082 65535 f
    0000000083 65535 f
    0000000084 65535 f
    0000000085 65535 f
    0000000086 65535 f
    0000000087 65535 f
    0000000088 65535 f
    0000000089 65535 f
    0000000090 65535 f
    0000000091 65535 f
    0000000092 65535 f
    0000000093 65535 f
    0000000094 65535 f
    0000000095 65535 f
    0000000096 65535 f
    0000000097 65535 f
    0000000098 65535 f
    0000000099 65535 f
    0000000100 65535 f
    0000000101 65535 f
    0000000102 65535 f
    0000000103 65535 f
    0000000104 65535 f
    0000000105 65535 f
    0000000106 65535 f
    0000000107 65535 f
    0000000108 65535 f
    0000000109 65535 f
    0000000110 65535 f
    0000000111 65535 f
    0000000112 65535 f
    0000000113 65535 f
    0000000114 65535 f
    0000000115 65535 f
    0000000116 65535 f
    0000000117 65535 f
    0000000118 65535 f
    0000000119 65535 f
    0000000120 65535 f
    0000000121 65535 f
    0000000122 65535 f
    0000000123 65535 f
    0000000124 65535 f
    0000000125 65535 f
    0000000126 65535 f
    0000000127 65535 f
    0000000128 65535 f
    0000000129 65535 f
    0000000130 65535 f
    0000000131 65535 f
    0000000132 65535 f
    0000000133 65535 f
    0000000134 65535 f
    0000000135 65535 f
    0000000136 65535 f
    0000000137 65535 f
    0000000138 65535 f
    0000000139 65535 f
    0000000140 65535 f
    0000000141 65535 f
    0000000142 65535 f
    0000000143 65535 f
    0000000144 65535 f
    0000000145 65535 f
    0000000146 65535 f
    0000000147 65535 f
    0000000148 65535 f
    0000000149 65535 f
    0000000150 65535 f
    0000000151 65535 f
    0000000152 65535 f
    0000000153 65535 f
    0000000154 65535 f
    0000000155 65535 f
    0000000000 65535 f
    0000073585 00000 n
    0000073976 00000 n
    0000126085 00000 n
    0000126473 00000 n
    0000126824 00000 n
    0000127135 00000 n
    0000159029 00000 n
    0000159324 00000 n
    0000159602 00000 n
    0000159822 00000 n
    0000159984 00000 n
    0000172276 00000 n
    0000172304 00000 n
    0000175567 00000 n
    0000175613 00000 n
    trailer
    &lt;&lt;4209A6BAF0B48847A4641458F7144A4B&gt;] &gt;&gt;
    startxref
    176234
    %%EOF
    xref
    0 0
    trailer
    &lt;&lt;4209A6BAF0B48847A4641458F7144A4B&gt;] /Prev 176234/XRefStm 175613&gt;&gt;
    startxref
    179814
    %%EOF</j></s></k></v></x></vp></g></s></r></m></y1></r></b></h></e></z></g.></v></ru0></s></ss></qz></y></c></r></t></d></h></k></y></v></c></f></yd></j-></b></e></s></lu></d></j></x></d></r></r></a></x></o></v></k></f0e></p></q></m></k></t></t></o></w></p></n:></t></i></t></n></m></r></j></z></k></zv></gn></l></s></h></h></y></b></a></lv></at></e></g></t></y></q></r></h></h></h></l></h></e></r></i></x></bp></l6></r></v0></l></h></p></body></html>

    Continue reading...

Compartilhe esta Página