from bs4 import BeautifulSoup
import requests
import os def getdepotdetailcontent(title,url):#爬取每个仓库列表的详情
r=requests.get("https://www.50yc.com"+url).content
soup = BeautifulSoup(r,"html.parser")
result = soup.find(name='div',attrs={"class":"sm-content"})#返回元素集
content = result.find_all("li")#返回元素集
with open(os.getcwd()+"\\depot\\"+title+"\\depotdetail.txt","w") as f :
for i in content:
b = i.find("span").text
br = i.find("div").text
f .write(b.replace(" ","").replace("\n","")+br.replace(" ","")+"\n"+"****************************"+"\n")
f.close() def getdepot(page):#爬取仓库列表信息
depotlisthtml = requests.get("https://www.50yc.com/xan"+page).content
content = BeautifulSoup(depotlisthtml,"html.parser")
tags = content.find_all(name="div",attrs={"class":"bg-hover"})
for i in tags:
y = i.find_all(name="img")#返回tag标签
for m in y:
if m["src"].startswith("http"):
imgurl = m["src"]
print(imgurl)
title = i.strong.text
depotdetailurl = i.a['href']
# print(depotdetailurl)
os.mkdir(os.getcwd()+'\\depot\\'+title+'\\')
with open(os.getcwd()+'\\depot\\'+title+'\\'+"depot.jpg","wb") as d :
d.write(requests.get(imgurl).content)
with open(os.getcwd()+'\\depot\\'+title+'\\'+"depot.txt","w") as m:
m.write(i.text.replace(" ",""))
m.close()
getdepotdetailcontent(title,depotdetailurl) for i in range(1,26):#爬取每页的仓库列表与仓库详情
getdepot("/page"+str(i))
print("/page"+str(i))

爬取内容为:

爬取结果如下:

[原创]python+beautifulsoup爬取整个网站的仓库列表与仓库详情的更多相关文章

  1. python爬虫--爬取某网站电影信息并写入mysql数据库

    书接上文,前文最后提到将爬取的电影信息写入数据库,以方便查看,今天就具体实现. 首先还是上代码: # -*- coding:utf-8 -*- import requests import re im ...

  2. python爬虫--爬取某网站电影下载地址

    前言:因为自己还是python世界的一名小学生,还有很多路要走,所以本文以目的为向导,达到目的即可,对于那些我自己都没弄懂的原理,不做去做过多解释,以免误人子弟,大家可以网上搜索. 友情提示:本代码用 ...

  3. Python爬虫学习之使用beautifulsoup爬取招聘网站信息

    菜鸟一只,也是在尝试并学习和摸索爬虫相关知识. 1.首先分析要爬取页面结构.可以看到一列搜索的结果,现在需要得到每一个链接,然后才能爬取对应页面. 关键代码思路如下: html = getHtml(& ...

  4. Python多线程爬取某网站表情包

    # 爬取网络图片import requestsfrom lxml import etreefrom urllib import requestfrom queue import Queue # 导入队 ...

  5. python 爬虫 爬取序列博客文章列表

    python中写个爬虫真是太简单了 import urllib.request from pyquery import PyQuery as PQ # 根据URL获取内容并解码为UTF-8 def g ...

  6. Python 利用 BeautifulSoup 爬取网站获取新闻流

    0. 引言 介绍下 Python 用 Beautiful Soup 周期性爬取 xxx 网站获取新闻流: 图 1 项目介绍 1. 开发环境 Python: 3.6.3 BeautifulSoup:   ...

  7. 利用python的requests和BeautifulSoup库爬取小说网站内容

    1. 什么是Requests? Requests是用Python语言编写的,基于urllib3来改写的,采用Apache2 Licensed 来源协议的HTTP库. 它比urllib更加方便,可以节约 ...

  8. python之简单爬取一个网站信息

    requests库是一个简介且简单的处理HTTP请求的第三方库 get()是获取网页最常用的方式,其基本使用方式如下 使用requests库获取HTML页面并将其转换成字符串后,需要进一步解析HTML ...

  9. Python使用urllib,urllib3,requests库+beautifulsoup爬取网页

    Python使用urllib/urllib3/requests库+beautifulsoup爬取网页 urllib urllib3 requests 笔者在爬取时遇到的问题 1.结果不全 2.'抓取失 ...

随机推荐

  1. aiohttp_spider

    aiohttp_spider_def: import asyncio import re import aiohttp import aiomysql from pyquery import PyQu ...

  2. GraphSage:

    https://yq.aliyun.com/articles/712465?type=2 讲了最基本的概念: 1.b.常见的欧几里得结构化数据 将数据转换到欧几里得空间中,所得到的数据称为欧几里得结构 ...

  3. RPC调用和HTTP调用的区别

    很长时间以来都没有怎么好好搞清楚RPC(即Remote Procedure Call,远程过程调用)和HTTP调用的区别,不都是写一个服务然后在客户端调用么?这里请允许我迷之一笑~Naive!本文简单 ...

  4. 教你用好 Javascript 数组

    原文链接:https://juejin.im/post/5d9769b26fb9a04df26c1b89 作为 Javascript 的标准对象之一,数组是非常底层而且实用的数据结构.虽然结构很简单, ...

  5. hw笔试题-01

    #include <stdlib.h> #include <stdio.h> #include <string.h> int str_split(char *inp ...

  6. linux jdk1.8 32位下载永久地址,ubuntu,centos,java

    链接: https://pan.baidu.com/s/16zSC0HZGFjrTAXrW6eyHzg 提取码: cj7m 复制这段内容后打开百度网盘手机App,操作更方便哦

  7. .NET Core 中间件之压缩、缓存

    前言 今天给大家介绍一下在 ASP.NET Core 日常开发中用的比较多的两个中间件,它们都是出自于微软的 ASP.NET 团队,他们分别是Microsoft.AspNetCore.Response ...

  8. maven打包时生成源代码

    <build> <finalName>${artifactId}</finalName> <plugins> <plugin> <ar ...

  9. conda基本知识

    卸载anaconda: rm -rf anaconda3 (anaconda文件夹名称) conda删除虚拟环境 在终端执行:conda remove -n your_env_name(虚拟环境名称) ...

  10. C# NPOI Export DataTable C# NPOI导出DataTable 单元格自适应大小

    1.Install-Package NPOI -v 2.4.0 2. using NPOI.XSSF; using NPOI.XSSF.UserModel; using NPOI.SS.UserMod ...