スナックelve 本店

バツイチ40代女の日記です

罠www

ンなわけで数えてみたんだけど、結果825。うーん? 少なくね? 何処で間違えたかな?

最初にarchiveページの下の部分でページを全部取得したと思ってたのね
f:id:elve:20180321090855p:plain

10ページ目をみてみたら
f:id:elve:20180321091003p:plain

ああああああああああ。根本から考え直しや~ヽ(^o^)丿

現状はこんな感じです

# coding: UTF-8
import requests
from bs4 import BeautifulSoup

# アクセスするURL
url = "http://d.hatena.ne.jp/elve/archive"

# URLにアクセスする htmlが帰ってくる(タグ付き)
html = requests.get(url)         #requestsを使って、webから取得
# htmlをBeautifulSoupで扱う
soup = BeautifulSoup(html.text,'lxml')
#記事のページリストを取得
lsPageDiv = soup.find('div',class_="calendar", id="pager-top")
lsPage = lsPageDiv.find_all('a')
cnt = 0
for l in lsPage:

    #<div class="day">の
    #<li class="archive archive-section">を
    #数える
    lsSectionsDiv = soup.find('div',class_="day")
    lsSections = lsSectionsDiv.find_all('li',class_="archive archive-section")
    #要素数
    cnt = cnt + len(lsSections)
    
    #requestsを使って、webから取得
    html = requests.get(l['href'])         
    # htmlをBeautifulSoupで扱う
    soup = BeautifulSoup(html.text,'lxml')
else:
    #数える
    lsSectionsDiv = soup.find('div',class_="day")
    lsSections = lsSectionsDiv.find_all('li',class_="archive archive-section")
    #要素数
    cnt = cnt + len(lsSections)
    print(cnt)