Home > Enterprise >  web scraping by beautiful soup return error?
web scraping by beautiful soup return error?

Time:11-05

HTML tags appears is the CSV file

HTML tags appears is the CSV file

CodePudding user response:

Here is updated version of your code.

import requests
from bs4 import BeautifulSoup
import csv
import os

csv_file = open(os.getcwd() "\data.csv", "a", newline="")
csv_writer = csv.writer(csv_file)
csv_writer.writerow(["job_title", "company_name", "location", "job_skills", "link"])

result=requests.get('https://wuzzuf.net/search/jobs/?q=python&a=hbp') 
soup=BeautifulSoup(result.content,'lxml') 

base_url = "https://wuzzuf.net"

# find all job posts card
job_posts = soup.find_all("div", {"class": "css-1gatmva e1v1l3u10"})

for job_post in job_posts: 
    job_title = job_post.find("h2", {"class": "css-m604qf"}).find("a").text
    company_name = job_post.find("div", {"class" : "css-d7j1kk"}).find("a").text[:-2]
    location = job_post.find("div", {"class" : "css-d7j1kk"}).find("span").text
    job_skills = job_post.find("div", {"class" : "css-1lh32fc"}).find_next_sibling("div").text

    link = job_post.find("h2", {"class": "css-m604qf"}).find("a")["href"]
    link_full = base_url   link

    csv_writer.writerow([job_title,company_name,location,job_skills,link_full])

csv_file.close()
  • Related