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. SpringCloud学习笔记(五、SpringCloud Netflix Hystrix)

    目录: Hystrix简介 线程隔离:线程池.信号量 服务降级.服务熔断.请求缓存.请求合并 Hystrix完整流程.Hystrix属性值 注解方式实现Hystrix Hystrix Dashboar ...

  2. 5. git-lab 项目操作

    项目操作 一.给成员授权项目权限 之前我们是给组增加成员.  当有的项目需要给组下面的成员授权不一样的时候. 我们需要在项目里面给成员授权权限 点击管理区域 点这个项目 看下图,我们可以看到  现在这 ...

  3. 计算多个点中距离最远的两个点 python

    import numpy as npfrom scipy import spatial print("hello")# test pointspts = np.random.ran ...

  4. [C10] 异常检测(Anomaly Detection)

    异常检测(Anomaly Detection) 问题的动机 (Problem Motivation) 异常检测(Anomaly detection)问题是机器学习算法中的一个常见应用.这种算法的有趣之 ...

  5. LG2444/BZOJ2938 「POI2000」病毒 AC自动机

    问题描述 LG2444 BZOJ2938 I \(\mathrm{AC}\)自动机 \(\mathrm{AC}\)自动机是一种多模式串匹配算法,本萌新今天刚学了它qwq 约定在构造\(\mathrm{ ...

  6. js判断为空

    function isEmpty (va){    if("undefined" == va){        return true;    }    if(null == va ...

  7. NETCore下IConfiguration和IOptions的用法(转载)

    原文:https://www.jianshu.com/p/b9416867e6e6 新建一个NETCore Web API项目,在Startup.cs里就会开始使用IConfiguration和IOp ...

  8. spring boot 开启https

    1.生成证书 keytool -genkey -alias tomcat -keyalg RSA -keystore E:/https.keystore 将生成好的证书放在项目根目录即可 2 修改配置 ...

  9. IM开发者的零基础通信技术入门(三):国人通信方式的百年变迁

    [来源申明]本文原文来自:微信公众号“鲜枣课堂”,官方网站:xzclass.com,原题为:<中国通信的百年沉浮>,本文引用时已征得原作者同意.为了更好的内容呈现,即时通讯网在收录时内容有 ...

  10. ThinkPHP 3.2 自定义基类 Model

    ThinkPHP 提供了一个 Model 类,供其他的 Model 进行继承.Model 类中是 MVC 中的模型类,它是调用 持久层 的上层类.感觉这么描述问题很多,但是有什么办法呢?但是,这个 M ...