Python crawler one-click to crawl beautiful pictures (three times scored)

I. Introduction

Every time I come into contact with a new crawler tool, I like to use various wallpaper sites to try it out, "4k beauties", scored three times. I'm here again. Try the use of PyQuery today .

Second, the realization process

1. Understand the basic use of PyQuery

Here I am referencing a blogger’s article: Portal

2. Have a certain understanding of web pages

I have scored three times. Can I understand this website? Website Portal For the
first time friends, you can read my previous article analyzing this website, Article Portal

3. Run the code

from pyquery import PyQuery as pq
import requests

url = 'http://pic.netbian.com/4kmeinv/'
html = requests.get(url=url).text
doc_1 = pq(html)  # 字符串初始化
data_s = doc_1('.slist .clearfix li a').items()  # 使用CSS选择器进行定位,定位节点过多,需要遍历一下
for list_s in data_s:
    image_url = 'http://pic.netbian.com/' + list_s.attr.href  # 提取a节点中的href属性,并得到一个新的链接
    image = requests.get(image_url).text  # 访问第二个页面
    doc_2 = pq(image)  # 字符串初始化
    contents = 'http://pic.netbian.com/' + doc_2('#img img').attr.src  # 依然是CSS选择器,提取img节点的src属性
    print(contents)  # 打印链接结果

Here is just a link to the final high-definition big picture of the picture. If you download it, please refer to the above article.

4. Running results

Insert picture description here
Insert picture description here

Supplement : I originally wanted to record a gif for the running result. As a result, except for the first run which was faster, the other times the speed was slower. I don't know if it is because of the internet speed. Big guys are welcome to give some suggestions in the comment area

Guess you like

Origin blog.csdn.net/qq_44921056/article/details/114124982