【Python】ヤフオク!スクレイピング ニンテンドーで検索した結果をDataframeで表示

未分類
import time
import requests,bs4
from bs4 import BeautifulSoup
import pandas as pd

columns = ["maker","name","price","count"]
df = pd.DataFrame(columns=columns)

r = requests.get('https://auctions.yahoo.co.jp/search/search?p=%E3%83%8B%E3%83%B3%E3%83%86%E3%83%B3%E3%83%89%E3%83%BC%E3%82%B9%E3%82%A4%E3%83%83%E3%83%81&va=%E3%83%8B%E3%83%B3%E3%83%86%E3%83%B3%E3%83%89%E3%83%BC%E3%82%B9%E3%82%A4%E3%83%83%E3%83%81&is_postage_mode=1&dest_pref_code=11&exflg=1&b=1&n=50')
soup = bs4.BeautifulSoup(r.text, "html.parser")

products =soup.find_all('li',attrs={'class':'FilterItem--product'})

time.sleep(5)
for product in products:
  #print(product)
  maker= product.find("p",{"class":"FilterItem__maker"}).text
  name= product.find("p",{"class":"FilterItem__name"}).text
    price = product.find("p",{"class":"FilterItem__price"}).text
    count = product.find("p",{"class":"FilterItem__count"}).text
    price=price.replace("\n","")

    #print(maker,name,price, count)
    se=pd.Series([maker,name,price, count],columns)
    #df = df.append(se, columns)    ---使用不可!
    df = pd.concat([df,pd.DataFrame([se])], axis=0)

df

タイトルとURLをコピーしました