量化交易QQ群488059390(里面大量专业视频教程和图书欢迎加入)
import requests # 导入requests包
from bs4 import BeautifulSoup
from urllib import request
from fake_useragent import UserAgent
#循环出所有页面
for num in range(3):
# print(str(num)+' :'+str(UserAgent().random))
headers = {
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Upgrade-Insecure-Requests': '1',
'User-Agent': str(UserAgent().random),
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Language': 'zh-CN,zh;q=0.9',
}
response = requests.get('http://www.user-agent.cn/', headers=headers, verify=False)
response.encoding = 'utf-8'
print('**************************')
print(response.text)