|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
把很多网址放在一个txt文档里面,一行一个,想下载网页源码,保存在指定的文件夹内,格式.html
请问需要用到那些模块。
f=open(r'C:\Users\Admin\Desktop\111.txt','r')
for i in f:
html=urllib.request.urlopen(i).read().decode('utf-8','ignore')
print(html)
小白只能写到这里了 ,用urllib.request.urlretrieve() 下载报错,不知道哪里出错了。
- def get_urls():
- with open("urls.txt") as urls:
- for url in urls:
- url = url.replace("\n", "")
- response = requests.get(url)
- ... #拿到响应,写入文件
复制代码
urls.txt
- https://fishc.com.cn/
- https://fishc.com.cn/
- https://fishc.com.cn/
复制代码
|
|