だから基本的に。私は2つのクラスを持っています。1つは靴の発売日です。もうひとつはその日に発売されたシューズ。ただし、これらはまったく異なる 2 つのクラスです。だから私はこれらのクラスからこすり取ろうとしています。すべての日付を含む「月のヘッダー」。そして、次のクラスであるスニーカー ポスト メインには、月ヘッダーの日付からすべての靴が含まれています。ただし、これらは 2 つの異なるクラスです。それらは互いにリンクされていません。そこで、h4 クラスから .nextSibling を実行して、「セクション」クラスをキャッチしようとしました。そのようには機能しませんでした。
<h4 class="month-header">April 15, 2016</h4>
<section class = "sneaker-post-main">...</section>
<section class = "sneaker-post-main">...</section>
<section class = "sneaker-post-main">...</section>
<h4 class="month-header">April 16, 2016</h4>
<section class = "sneaker-post-main">...</section>
<section class = "sneaker-post-main">...</section>
<section class = "sneaker-post-main">...</section>
<h4 class="month-header">April 17, 2016</h4>
<section class = "sneaker-post-main">...</section>
<section class = "sneaker-post-main">...</section>
<section class = "sneaker-post-main">...</section>
また、私の HTML が意味をなさない場合、これは私がスクレイピングしている Web サイトです。http://sneakernews.com/air-jordan-release-dates/ 日付が辞書のキーで、値がその日付にリリースされる靴のリストのように見えるようにしたかったのです。以下に示すように。
April 16 2015
{
Shoe info 1
Shoe info 2
Shoe info 3
}
April 17 2015
{
Shoe info 1
Shoe info 2
Shoe info 3
}
BeautifulSoup を使用してこのタスクを実行しようとしています。私はそれを理解できないようです。2016 年 4 月 15 日 -> リリース日 HTML です。... -> 靴の情報 etectra が含まれています。
from bs4 import BeautifulSoup
import requests
import json
headers = {
#'Cookie': 'X-Mapping-fjhppofk=FF3085BC452778AD1F6476C56E952C7A; _gat=1; __qca=P0-293756458-1459822661767; _gat_cToolbarTracker=1; _ga=GA1.2.610207006.1459822661',
'Accept-Encoding': 'gzip, deflate, sdch',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36,(KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36',
'Accept-Language': 'en-US,en;q=0.8',
'Accept': '*/*',
'Connection': 'keep-alive',
'Content-Length': 0
}
response = requests.get('http://sneakernews.com/air-jordan-release-dates/',headers=headers).text
soup = BeautifulSoup(response)
for tag in soup.findAll('h4', attrs = {'class':'month-header'}):
print tag.nextSibling.nextSibling.nextSibling
これはこれまでの私のコードです!