【问题标题】:Web scraping Indeed, can't get full job description, python网络抓取确实,无法获得完整的职位描述,python
【发布时间】:2020-09-22 19:57:49
【问题描述】:

我需要你的帮助。当抓取 Indeed 没有完整的职位描述时,需要扩展职位以查看整个职位描述。我不知道如何解决它。请帮忙。

提前谢谢你,

代码如下:

import requests
from bs4 import BeautifulSoup
import csv


class JobInformation:
def __init__(self):
    self.job_information = []
    self.job_information_dict = {}

def get_data(self):
    for i in range(50):
        id = 10
        URL ='https://www.indeed.com/jobs?q=%22cable+technician%22&radius=25&sort=date{id}'
        page = requests.get(URL)

        soup = BeautifulSoup(page.content, 'html.parser')
        job_elements = soup.find_all(class_="jobsearch-SerpJobCard")

        for job_element in job_elements:
            job_title = job_element.find('a', class_='jobtitle')
            job_company = job_element.find(class_="company")
            job_summary = job_element.find(class_='summary')
            job_location = job_element.find(class_='location')
            job_date_posted = job_element.find(class_='date')

            self.job_information_dict = {
                'title': job_title.text.strip(),
                'company': job_company.text.strip(),
                'summary': job_summary.text.strip(),
                'location': job_location.text.strip(),
                'date': job_date_posted.text.strip(),
            }
            self.job_information.append(self.job_information_dict)

        f = open('jobinfo.csv', 'w')
        fieldnames = ['title', 'company',
                      'summary', 'location', 'date']

        with f:
            writer = csv.DictWriter(f, fieldnames=fieldnames)
            writer.writeheader()

            for self.data in self.job_information:
                writer.writerow(self.data)

    print("Writing to csv successful...")
    id = +10


ji = JobInformation()

ji.get_data()

【问题讨论】:

  • 我遇到了同样的问题。你找到解决办法了吗?
  • 我只是添加这个以防你不知道但抓取 Indeed.com 违反他们的服务条款,请参阅indeed.com/legal?hl=en&redirect=true“使用任何自动化系统或软件,无论是由第三方还是其他方式操作, 禁止从网站中提取数据(例如屏幕抓取或抓取)”。

标签: python web-scraping


【解决方案1】:

我的解决方法是使用job_element.h2.a.get('href') 获取每个职位的部分 URL

将其与服务器 URL 相结合,您可以转到特定的职位。例如:

jobURL = "http://indeed.com" + job_element.h2.a.get('href')

但是,您需要为每个职位发布发送一个新的 HTTP 请求,但您可以从那里获取完整的职位描述。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-06
    • 1970-01-01
    相关资源
    最近更新 更多