简体   繁体   中英

Converting single-column scraped data csv in Python

very basic, trying to download list of job titles to csv. I can see the data I want in the environment. When I export to csv, there is no data. Sharing the code of the data before I began applying csv.

import requests
from bs4 import BeautifulSoup 

url = 'https://www.payscale.com/research/US/Job/Accounting-and-Finance'

for jobs in soup.find_all ('a', class_ = "subcats__links__item") :
    print(jobs.text)

I tried running the following code and it worked fine:

import requests
from bs4 import BeautifulSoup 
import csv
import os

# setup the default file lookup location to cwd
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))


url = 'https://www.payscale.com/research/US/Job/Accounting-and-Finance'

# get the response from the url provided
response = requests.get(url)

soup = BeautifulSoup(response.text, 'html.parser')

job_data = []

with open(os.path.join(__location__,'output.csv'), 'w+') as f:
    writer = csv.writer(f)
    for jobs in soup.find_all('a', class_ = "subcats__links__item"):
        job_data.append(jobs.text)
    writer.writerow(job_data)

This creates a csv file with comma separated 'job headers'.

CSV Output: Accountant,Staff Accountant,Financial Analyst,Senior Accountant,Financial Controller,Accounting Manager,Senior Financial Analyst,Associate - Accounting or Auditing Firm,Finance Manager,Corporate Controller,Finance Director,Certified Public Accountant (CPA),Assistant Controller,Senior Manager Accountant / Auditor,Financial Advisor,"Branch Manager, Banking",Credit Analyst,Underwriter,Compliance Specialist,Auditor,Compliance Officer,Compliance Manager,Compliance Analyst,Tax Manager,Internal Auditor,Accounting Supervisor,Tax Accountant,"Business Analyst, Finance/Banking","Assistant Branch Manager, Banking",Portfolio Manager,Loan Officer,Senior Auditor,Senior Underwriter,Senior Tax Accountant,Tax Associate,Risk Manager,Senior Staff Accountant,Credit Manager,Project Accountant,Junior Accountant,Senior Internal Auditor,Risk Analyst,Director of Finance & Administration,Cost Accountant,Investment Analyst,Compliance Director,Tax Preparer,Fraud Investigator,Associate Auditor,Accounting Director,Senior Finance Manager,Asset Manager,Budget Analyst,Financial Manager,Financial Counselor,Accounting Analyst,Insurance Underwriter,Treasury Analyst,Financial Planner,Plant Controller,Universal Banker,Staff Auditor,Underwriting Assistant,Internal Auditing Manager,Financial Coordinator,Auditing Manager,Senior Tax Manager,"Manager, Financial Planning & Analysis",Certified Financial Planner (CFP),Financial Consultant,Regulatory Compliance Manager,Property Accountant,Entry-level Staff Accountant,Senior Credit Analyst,Tax Analyst,Finance Analyst,Payroll Accountant,Bank Manager,Finance Associate,Director of Finance,Enrolled Agent,Financial Accountant,Fraud Analyst,Tax Director,Compliance Auditor,Senior Information Technology (IT) Auditor,"Loan Officer, Commercial",Senior Compliance Analyst,"Vice President, Compliance Officer",Par aplanner,Treasurer,Quantitative Analyst,Senior Manager Auditor,Treasury Manager,Internal Audit Director,"Senior Analyst, Finance",Assistant Controller (Financial),Comptroller (Financial),Financial Specialist,Mortgage Loan Officer

Thanks, Anshul

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM