美文网首页python爬虫代码
爬取彼岸图python数据

爬取彼岸图python数据

作者: 逢笔生辉 | 来源:发表于2023-02-28 21:28 被阅读0次

import requests

import parsel

def requserurl(url1,headers,data):

response=requests.get(url1,headers=headers)

contents=response.content.decode(response.apparent_encoding)

m=parsel.Selector(contents)

u=m.xpath('//div[@class="slist"]/ul[@class="clearfix"]/li/a')

for iin u:

href=i.xpath('./@href')

alt=i.xpath('./img/@alt')

data.append((alt.get(),href.get()))

def store(data,headers):

for iin data:

url2='https://pic.netbian.com'+i[1]

response=requests.get(url2,headers=headers)

constens2=response.content.decode(response.apparent_encoding)

m = parsel.Selector(constens2)

y = m.xpath("//a[@id='img']/img/@src").get()

newurl='https://pic.netbian.com'+y

response=requests.get(newurl,headers=headers)

path=r"C:\Users\29258\Pictures\Saved Pictures\\"+i[0]+'.jpg'

        with open(path,'wb')as f:

f.write(response.content)

def kongzhi():

name =input('输入你要搜的')

index =input('输入页数')

headers = {

'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.78'}

data = []

for iin index:

url ='https://pic.netbian.com/4k{name}/index_{index}.html'.format(name=name, index=i)

requserurl(url,headers,data)

store(data,headers=headers)

if __name__=='__main__':

kongzhi()

相关文章

网友评论

    本文标题:爬取彼岸图python数据

    本文链接:https://www.haomeiwen.com/subject/tdzlldtx.html