Introduction to reptiles in Python (the most detailed and easy-to-understand explanation)

Introduction to reptiles and small cases, we will learn how to crawl website pictures, videos

First, we need to import the request package
, then define the address we want to visit, simulate the browser to send the request, and get the returned content,
and finally, download the content we need by **urllib.request.urlretrieve()** method, And in the file where we installed Python, just open the folder to view it.

# 使用urllib 来获取百度首页的基本源码
# 1首先定义一个url即将要访问的地址
import urllib.request
url = 'http://www.baidu.com'
# 模拟浏览器向服务器发送请求
# read()返回是字节码式二进制数据
# 我们要将二进制数据转换为字符串
# 二进制 -》 字符串,解码 decode('编码的格式')
response = urllib.

Guess you like

Origin blog.csdn.net/a910247/article/details/125906284