python爬虫——https请求

python爬虫——https请求

from urllib.request import Request,urlopen
from fake_useragent import UserAgent
import ssl
url = "https://www.12306.cn/index/"
headers = {
    "User-Agent":UserAgent().random
}
request = Request(url,headers = headers)
#忽略SSL证书
# context = ssl._create_unverified_context()
response = urlopen(request)# urlopen(request,context)
print(response.read().decode())

#忽略SSL证书python爬虫——https请求_第1张图片

你可能感兴趣的:(小白学python,零基础学python,学会就能进大厂,https,python,爬虫)