两种方式.

1,requests


#!/usr/bin/env python
# -- coding: utf-8 --
import requests
import ssl
requests.packages.urllib3.disable_warnings()
url = 'https://www.douban.com/'
c = requests.get(url,timeout=5,verify=False)
html = c.text
print html
#print html.encode("GBK", 'ignore'); 
exit()

如果是用cmd下面调试,要用encode gbk.

2,pycurl


#!/usr/bin/env python
# -- coding: utf-8 --
import pycurl
import certifi
url = 'https://202.55.9.30/'
c = pycurl.Curl()
c.setopt(c.URL, url)
c.setopt(pycurl.CAINFO, certifi.where())
# Follow redirect.
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(c.SSL_VERIFYHOST,False);
c.setopt(c.SSL_VERIFYPEER,False);
html = c.perform()
c.close()
print html;
#print html.encode("GBK", 'ignore');
exit()

4,urllib2


#!/usr/bin/env python
# -- coding: utf-8 --
import urllib2
import ssl

ssl._create_default_https_context = ssl._create_unverified_context
f = urllib2.urlopen("https://202.55.9.30/")
html = f.read()
f.close()
print html

标签: none

添加新评论