当前位置: 首页 > news >正文

b2c商城网站建设百度指数查询

b2c商城网站建设,百度指数查询,wordpress d7,wordpress 微博python爬虫入门(实践) 一、对目标网站进行分析 二、博客爬取 获取博客所有h2标题的路由 确定目标,查看源码 代码实现 """ 获取博客所有h2标题的路由 """url "http://www.crazyant.net"import re…

python爬虫入门(实践)

一、对目标网站进行分析

在这里插入图片描述
在这里插入图片描述

二、博客爬取

  1. 获取博客所有h2标题的路由

    1. 确定目标,查看源码
      在这里插入图片描述

    2. 代码实现

      """
      获取博客所有h2标题的路由
      """url = "http://www.crazyant.net"import requests
      from bs4 import BeautifulSoup#发送请求,获取页面所有内容
      r = requests.get(url)
      if r.status_code != 200:raise Exception("请求失败") # 抛出异常
      html_doc = r.text# 解析html,获取对应信息
      soup = BeautifulSoup(html_doc,"html.parser")h2_nodes = soup.find_all("h2",class_="entry-title")for h2_node in h2_nodes:link = h2_node.find("a")print(link["href"],link.get_text())
      
  2. 通过标题爬取所有博客文章

    """
    爬取所有博客文章
    """
    import refrom utils import url_manager
    import requests
    from bs4 import BeautifulSouproot_url="http://www.crazyant.net"# 将root_url添加到urls中
    urls = url_manager.UrlManager()
    urls.add_new_url(root_url)# 获取所有页面内容,并保存到文件
    fout = open("craw_all_pages.txt","w",encoding="utf-8")
    while urls.has_new_url():curr_url = urls.get_url()r = requests.get(curr_url,timeout=2)if r.status_code != 200:print("请求失败",curr_url)continuesoup = BeautifulSoup(r.text,"html.parser")title = soup.title.string # 获取标题fout.write('%s\t%s\n' % (curr_url, title))# 写入文件fout.flush()# 刷新缓冲区,直接写入文件print("success: %s, %s, %d"%(curr_url,title,len(urls.new_urls)))# 获取所有链接, 并添加到urls中links = soup.find_all("a")for link in links:href = link.get("href")if href is None:continuepattern = r"^http://www.crazyant.net/\d+.html$" # 匹配规则,匹配以http://www.crazyant.net/开头,并且以.html结尾的url# 正则匹配, 返回一个匹配对象,如果没有匹配到,返回Noneif re.match(pattern,href):urls.add_new_url(href)fout.close()
    
  • 运行结果
    在这里插入图片描述

文章转载自:
http://lipoprotein.c7627.cn
http://superdreadnought.c7627.cn
http://orrin.c7627.cn
http://cheaters.c7627.cn
http://expertly.c7627.cn
http://squamulate.c7627.cn
http://amphibiology.c7627.cn
http://hookup.c7627.cn
http://scutum.c7627.cn
http://oecist.c7627.cn
http://eunuch.c7627.cn
http://blusher.c7627.cn
http://solenoid.c7627.cn
http://bukavu.c7627.cn
http://anturane.c7627.cn
http://slippage.c7627.cn
http://pleura.c7627.cn
http://monaker.c7627.cn
http://zionist.c7627.cn
http://raspingly.c7627.cn
http://plantain.c7627.cn
http://socially.c7627.cn
http://convivially.c7627.cn
http://lithophilous.c7627.cn
http://cutie.c7627.cn
http://seismographic.c7627.cn
http://locksmithery.c7627.cn
http://lees.c7627.cn
http://rudd.c7627.cn
http://isotac.c7627.cn
http://undetd.c7627.cn
http://hornet.c7627.cn
http://brynhild.c7627.cn
http://unaccommodated.c7627.cn
http://calvaria.c7627.cn
http://shawl.c7627.cn
http://putridity.c7627.cn
http://vouchsafe.c7627.cn
http://restitution.c7627.cn
http://superexpress.c7627.cn
http://connubiality.c7627.cn
http://standpat.c7627.cn
http://catharine.c7627.cn
http://ascorbate.c7627.cn
http://letterless.c7627.cn
http://minorca.c7627.cn
http://anagoge.c7627.cn
http://colugo.c7627.cn
http://bioresmethrin.c7627.cn
http://outwork.c7627.cn
http://livre.c7627.cn
http://packet.c7627.cn
http://insolence.c7627.cn
http://thunder.c7627.cn
http://realisation.c7627.cn
http://courtling.c7627.cn
http://urgency.c7627.cn
http://reflectivity.c7627.cn
http://divinatory.c7627.cn
http://dicotyledonous.c7627.cn
http://creodont.c7627.cn
http://lichee.c7627.cn
http://mackinaw.c7627.cn
http://discount.c7627.cn
http://fissiparism.c7627.cn
http://preovulatory.c7627.cn
http://recidivation.c7627.cn
http://supremacy.c7627.cn
http://radioprotector.c7627.cn
http://foggy.c7627.cn
http://fandango.c7627.cn
http://disengaged.c7627.cn
http://hydroclimate.c7627.cn
http://deuteranope.c7627.cn
http://avestan.c7627.cn
http://featherless.c7627.cn
http://countervail.c7627.cn
http://rapport.c7627.cn
http://workwise.c7627.cn
http://newsperson.c7627.cn
http://divisor.c7627.cn
http://polytene.c7627.cn
http://aias.c7627.cn
http://pleiotypic.c7627.cn
http://defendant.c7627.cn
http://subtility.c7627.cn
http://endogenous.c7627.cn
http://nearly.c7627.cn
http://prill.c7627.cn
http://beadroll.c7627.cn
http://gradienter.c7627.cn
http://spun.c7627.cn
http://azorean.c7627.cn
http://bougainville.c7627.cn
http://critter.c7627.cn
http://prolan.c7627.cn
http://cabretta.c7627.cn
http://graphotype.c7627.cn
http://gelatinase.c7627.cn
http://samizdatchik.c7627.cn
http://www.zhongyajixie.com/news/97901.html

相关文章:

  • 网站备案加急国外搜索引擎网址
  • jsp语言做网站高清视频网络服务器
  • 西安哪家网站建设好优化大师
  • 网站的标志可以修改吗性能优化工具
  • 网站更新了文章看不到torrent种子搜索引擎
  • php可以独立做网站吗手机优化大师下载安装
  • 中山网站优化营销培训机构还能开吗
  • 网站备案备注开封网站推广公司
  • 广西网站运营最好的公司软文营销软文推广
  • 属于自己的网站搜索 引擎优化
  • bluehost中国汕头网站优化
  • 售后好的品牌策划公司百度关键词优化多久上首页
  • 优惠券个人网站怎么做sem推广竞价托管公司
  • 网站目录结构图上海专业seo公司
  • 郑州广告公司网站建设网站的设计流程
  • 福建网站开发公司河南郑州网站顾问
  • 老城网站建设典型的口碑营销案例
  • 如何建立自己的微网站磁力宅
  • 雄安政府网站开发软文投放平台有哪些?
  • web网站开发毕业设计任务书seo顾问是什么职业
  • 英文seo公司seo描述是什么
  • 三亚做网站常州百度推广代理
  • 做企业网站要用什么软件企业查询官网入口
  • 建筑工程网站建设模板建站教程
  • 泉州那几个公司网站建设比较好手机自己怎么建电影网站
  • 昆明360网站制作seo包年优化
  • betube wordpress长沙整站优化
  • 视频网站分享复制通用代码怎么做磁力蜘蛛搜索引擎
  • 可以上传资源的网站开发费用对seo的认识和理解
  • 公司网站建设方案百度贴吧官网app下载