我正在开发一个项目,该项目读取包含ICS文件(icalendar)的网址。它不是将其作为字符串读取而是打印为字节需要一些建议。
import requests
url = "http://ical.keele.ac.uk/index.php/ical/ical/15021113"
c = requests.get(url)
c.encoding = 'ISO-8859-1'
print(c.content)
预期回报
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
实际回报
b"BEGIN:VCALENDAR\rVERSION:2.0\rPRODID:-//hacksw/handcal//NONSGML v1.0//EN\rBEGIN:VEVENT\r
我已经尝试直接使用ics文件并且没有任何问题但是当我从url请求时它不起作用。谢谢
答案 0 :(得分:1)
Delirious Lettuce是对的,只需使用文字:
http://docs.python-requests.org/en/master/user/quickstart/#response-content
import requests
url = "http://ical.keele.ac.uk/index.php/ical/ical/15021113"
c = requests.get(url)
#c.encoding = 'ISO-8859-1'
#print(c.content)
print(c.text[:10])
结果
BEGIN:VCAL
(3.6.1 32位窗口)