Three minutes to teach you to use Python to crawl your favorite young lady pictures

Use Python to crawl young lady pictures

First of all links on the site beautiful girls

Crawling pictures is mainly divided into the following steps:

1. Open a website of your favorite young lady

Eg xiaojiejie web

2. Download and install the python environment

Python official website
rookie tutorial-python environment construction tutorial

3. Start coding

Python all code is as follows

# requests 请求 需要提前在Terminal中安装 pip install requests
import os
import time

import requests
# re正则
import re
# 改变自己身份
headers = {
   'User-Agent': 'asbasdf'
}
# 请求网页
print("请输入你要爬取网站的链接")
httpurl = input()
response = requests.get(httpurl,headers = headers)
print(response.request.headers)
print(response.text)
html = response.text
# 解析网页
# view-source:https://www.vmgirls.com/15159.html
# 链接前加view-source查看网页源代码
dir_name = re.findall('<h1 class="post-title h1">(.*?)</h1>',html)[-1]
if not os.path.exists(dir_name):
   os.mkdir(dir_name)
# 正则查找
urls = re.findall('<a href="(.*?)" alt=".*?" title=".*?">',html)
print(urls)
# 保存图片
for url in urls:
   time.sleep(1)
   # 图片名字
   name = url.split('/')[-1]
   response = requests.get("https:"+url,headers = headers)
   print(name+"正在下载")
   with open(dir_name+'/'+name,'wb') as f:
       f.write(response.content)
print('下载完毕')

4. Run and download

Recommendation: 020 is continuously updated, the small circle of boutiques has new content every day, and the concentration of dry goods is extremely high.
There are everything you want to make connections and discuss technology!
Be the first to join the group and outperform your peers! (There is no fee for joining the group)
Click here to communicate and learn with Python developers.
Group number: 745895701
application and delivery :
Python software installation package, Python actual combat tutorial,
free collection of materials, including Python basic learning, advanced learning, crawling, artificial intelligence, automated operation and maintenance, automated testing, etc.

Guess you like

Origin blog.csdn.net/Python_xiaobang/article/details/113031888