OppaAI commited on
Commit
0296fc7
·
verified ·
1 Parent(s): 25c5665

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import os
2
  import gradio as gr
3
- import requests
4
  from bs4 import BeautifulSoup
5
  from urllib.parse import urlencode
6
  from fastmcp import FastMCP
@@ -11,7 +11,7 @@ mcp = FastMCP("Indeed Web Scraper Agent")
11
  @mcp.tool(name="search_jobs")
12
  def search_jobs_tool(query: str, location: str, limit: int = 10, salary: str = None, job_type: str = None):
13
  """
14
- Scrape jobs from Indeed website using requests + BeautifulSoup.
15
 
16
  Args:
17
  query (str): Job title or keywords to search for.
@@ -32,12 +32,10 @@ def search_jobs_tool(query: str, location: str, limit: int = 10, salary: str = N
32
  }
33
 
34
  url = base_url + urlencode(params)
35
- headers = {
36
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
37
- }
38
 
39
  try:
40
- response = requests.get(url, headers=headers)
 
41
  response.raise_for_status()
42
 
43
  soup = BeautifulSoup(response.text, "html.parser")
@@ -94,8 +92,8 @@ app = gr.Interface(
94
  gr.Textbox(label="Job Type (optional, ignored)")
95
  ],
96
  outputs="markdown",
97
- title="Indeed Job Search (with BeautifulSoup) + FastMCP",
98
- description="Search jobs by scraping Indeed.ca using requests and BeautifulSoup."
99
  )
100
 
101
  if __name__ == "__main__":
 
1
  import os
2
  import gradio as gr
3
+ import cloudscraper
4
  from bs4 import BeautifulSoup
5
  from urllib.parse import urlencode
6
  from fastmcp import FastMCP
 
11
  @mcp.tool(name="search_jobs")
12
  def search_jobs_tool(query: str, location: str, limit: int = 10, salary: str = None, job_type: str = None):
13
  """
14
+ Scrape jobs from Indeed website using cloudscraper + BeautifulSoup.
15
 
16
  Args:
17
  query (str): Job title or keywords to search for.
 
32
  }
33
 
34
  url = base_url + urlencode(params)
 
 
 
35
 
36
  try:
37
+ scraper = cloudscraper.create_scraper()
38
+ response = scraper.get(url)
39
  response.raise_for_status()
40
 
41
  soup = BeautifulSoup(response.text, "html.parser")
 
92
  gr.Textbox(label="Job Type (optional, ignored)")
93
  ],
94
  outputs="markdown",
95
+ title="Indeed Job Search (with BeautifulSoup + Cloudscraper) + FastMCP",
96
+ description="Search jobs by scraping Indeed.ca using cloudscraper and BeautifulSoup. Results sorted by most recent."
97
  )
98
 
99
  if __name__ == "__main__":