我使用Python的request
库访问(公共)ads.txt文件:
import requests
r = requests.get('https://www.sicurauto.it/ads.txt')
print(r.text)
在大多数情况下,此方法工作正常,但上面URL中的文本以一些奇怪的符号开头:
> google.com, [...]
如果在浏览器中打开URL,则看不到这三个符号。文字开头为google.com, [...]
,在编码和网络协议方面,我是一个初学者。这些奇怪的符号可能从哪里来?
答案 0 :(得分:1)
在调用Metadata-Version: 2.0
Name: pymongo
Version: 3.7.0
Summary: Python driver for MongoDB <http://www.mongodb.org>
Home-page: http://github.com/mongodb/mongo-python-driver
Author: Bernie Hackett
Author-email: bernie@mongodb.com
Installer: pip
License: Apache License, Version 2.0
Location: /usr/lib64/python2.7/site-packages
Requires:
Classifiers:
Development Status :: 5 - Production/Stable
Intended Audience :: Developers
License :: OSI Approved :: Apache Software License
Operating System :: MacOS :: MacOS X
Operating System :: Microsoft :: Windows
Operating System :: POSIX
Programming Language :: Python :: 2
Programming Language :: Python :: 2.6
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: Implementation :: PyPy
opic :: Database
You are using pip version 8.1.2, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
之前,您需要在r.encoding
中指定编码:
r.text