104的爬蟲
可以使用requests的套件來獲取api回傳結果,並使用BesutifulSoup, parsel等parser來將爬回來的html格式的資料
解析為字串,代碼如下:
import requests
from bs4 import BeautifulSoup
# 設定爬取的URL
url = 'https://www.104.com.tw/jobs/search/?keyword=測試/QA&jobcat=2007001000&area=6001001000'
# 發送GET請求並取得響應
response = requests.get(url)
# 檢查響應狀態碼,確保成功連接到網站
if response.status_code == 200:
    # 解析HTML頁面
    soup = BeautifulSoup(response.text, 'html.parser')
    
    # 獲取職缺列表
    job_list = soup.find_all('article', class_='js-job-item')
    
    for job in job_list:
        # 提取職缺標題
        title = job.find('a', class_='js-job-link').text.strip()
        
        # 提取公司名稱
        company = job.get('data-cust-name').strip()
        
        # 提取工作地點
        location = job.find('ul', class_='job-list-intro').find_all('li')[0].text.strip()
        
        # 提取薪資
        salary = job.find('span', class_='b-tag--default').text.strip()
        
        # 輸出職缺資訊
        print(f"職缺:{title}")
        print(f"公司:{company}")
        print(f"地點:{location}")
        print(f"薪資:{salary}")
        print("=" * 30)
else:
    print("連接網站失敗,狀態碼:", response.status_code)