爬zol村桌布篇

2022-02-27 08:22:54 字數 1146 閱讀 8218

# -*- coding: utf-8 -*-

# @author : jackzz

import requests,os

from pyquery import pyquery as pq

def get_request(url):

#構造請求頭

headers =

html = requests.get(url=url, headers=headers).content.decode("gb2312")#**編碼格式是2312具體看網頁原始碼

# print(html)

doc =pq(html)

items = doc('.photo-list-padding').items()

for item in items:

# print(item)

url_img = item.find('img').attr('src')

# print(url_img) #列印每個封面url

name = item.find('span').attr('title')

print(name)#獲取每個封面的標題

#獲取絕對路徑拼接

file_path=os.path.join(os.getcwd(),"imgs")

#判斷當前路徑是否存在,不存在則建立路徑

if not os.path.exists(file_path):

#建立路徑

os.makedirs(file_path)

#多頁爬取設定,爬取一到五頁

for i in range(1,5):

url=""%str(i)+'.html'

get_request(url)

python抓取zol付費桌布

僅限技術交流,禁止任何商業用途 學習了jack cui的爬蟲文章,頗有收穫。拿來練練手。點開第一張桌布 用到的兩個重要庫 selenium 和beautifulsoup,對庫不熟悉的,建議看學習一下。當乙個圖集結束時,再點下一張是會異常的,因為此時,控制項是不可見狀態的。這時候,繼續分析網頁 可以發...

scrapy 爬取桌布

scrapy startproject bizhi scrapy genspider bizhispider www.netbian.com 要爬取的桌布 網域名稱www.netbian.com 新建python檔案run.py from scrapy import cmdline cmdline....

爬取彼岸桌布

看到論壇上有人發,自己跟著敲了遍 有些地方進行了改動,學習了。coding utf 8 time 2020 6 17 18 24 author banshaohuan site file bizhi.py software pycharm import requests from bs4 impor...