Copy a network object denoted by a URL to a local file. If the URL points to a local file, the object will not be copied unless filename is supplied. Return a tuple (filename,
headers)where filename is the local file name under which
the object can be found, and headers is whatever the
info()method of the object returned by urlopen()returned
(for a remote object). Exceptions are the same as for
urlopen().
具体实现代码如下:
# -*- coding:utf-8 -*-
import time
from urllib import request
from bs4 import BeautifulSoup
import re
url = r'https://http://www.77cn.com.cn/question/22918070'
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'}