LoginSignup
1
2

求人サイトから、全企業の詳細情報を取得してエクセルに出力

Posted at

求人サイトから各企業の詳細urlを取得して、情報を取得、エクセルに出力するプログラムです。

結果

スクリーンショット 2023-06-05 14.59.27.png

各コード

全体コード

import requests
from bs4 import BeautifulSoup
import pandas as pd

# スクレイピング対象のURL
url = "https://job.mynavi.jp/25/pc/search/query.html?HR:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,99"


# データを保存するための空のリスト
data = []

# ページにアクセス
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')


# 各企業の詳細ページへのリンクを含む要素を取得
links = soup.select('a.js-add-examination-list-text')


#相対リンクをリンクリストに追加していく
link_list=[]
for link in links:
    link_list.append(link.get('href'))


#各詳細ページにアクセス

for link in link_list:
    response = requests.get('http://job.mynavi.jp'+link)
    soup = BeautifulSoup(response.text, 'html.parser')
      # 必要な情報を取得
    company_name = soup.select('h1')[0].text
    phone_number = soup.select('td#corpDescDtoListDescText220')[0].text
    data.append([company_name,phone_number])

# データをDataFrameに変換
df= pd.DataFrame(data, columns=['企業名', '電話番号'])

# DataFrameをExcelファイルに出力
df.to_excel('企業情報.xlsx', index=False)

1
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
1
2