【爬虫学习】一个简单的爬虫demo

##################################################
# 1. 请求页
import time
import requests
import re

headers = {
    'user-agent': 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36'

}
# response = requests.get('https://www.vmgirls.com/13591.html', headers=headers)
response = requests.get('http://www.mculover666.cn/posts/1606619423/', headers=headers)
html = response.text
# print(response.request.headers)
# print(response.text)

# 2. 解析网页
# urls = re.findall('', html)
# urls = re.findall('mark', html)
urls = re.findall('mark', html)
# mark
print(urls)
# for url in urls:
#     print(url.split('"')[1])

# 3. 保存图片
for url in urls:
    # 延时
    # time.sleep(1)
    url = url.split('"')[1]
    # print(url)
    # 图片的名字
    file_name = url.split('/')[-1].split('?')[0]
    print(file_name)
    response = requests.get(url, headers=headers)
    # with open(file_name, "wb") as f:
    #     f.write(response.content)

你可能感兴趣的:(#,python学习)