LoginSignup
0
2

ページ遷移して、スクレイピングした情報をexcel出力

Posted at

pythonで、検索ワードを入力し、webサイト上で検索したページから情報をスクレイピングし、excelにまとめるプログラムをクラウドワークスさんのサイトで作りました。

コード

import requests
from bs4 import BeautifulSoup
from openpyxl import Workbook

# 検索キーワードの入力
keyword = input("検索キーワードを入力してください: ")

# WebページのURL
url = "https://crowdworks.jp/public/jobs/search?keep_search_criteria=true&order=score&hide_expired=true&search%5Bkeywords%5D=" + keyword

# Webページの取得
response = requests.get(url)
html = response.text

# BeautifulSoupを使ってHTMLを解析
soup = BeautifulSoup(html, "html.parser")

# Excelファイルの作成とシートの作成
workbook = Workbook()
sheet = workbook.active

# タイトル、公開日、リンクのヘッダー行を追加
sheet.append(["タイトル", "期限", "リンク"])

# 検索結果の情報をスクレイピングしてExcelに書き出す
results = soup.find_all("div", class_="item_body job_data_body") # スクレイピング対象の要素を指定

for result in results:
    title = result.find("h3").text.strip()
    deadline = result.find("div", class_="post_date meta_column").text.strip()
    link = result.find("a")["href"]

    sheet.append([title, deadline, link])

# Excelファイルを保存
workbook.save("search_results.xlsx")

結果

スクリーンショット 2023-05-30 20.01.38.png

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2