爬取厦门地区职务表

1. 查找网址http://fj.huatu.com/zt/2019zwb/diqu/9.html

2.找到源代码

 3.爬取所需内容

 4.编写程序

import requests
from bs4 import BeautifulSoup
import pandas as pd
url="http://fj.huatu.com/zt/2019zwb/diqu/9.html"#爬取厦门职务
headers= {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3741.400 QQBrowser/10.5.3863.400'}#伪装爬虫
r=requests.get(url)#发送请求
r.encoding=r.apparent_encoding#统一编码
data=r.text
soup=BeautifulSoup(data,'html.parser')#使用“美味的汤”工具
x=[]#建立空列表
y=[]
for i in soup.find_all(class_="job_title"):#将目录放在空列表
x.append(i.get_text().strip())
for k in soup.find_all(class_="job_content"):#将职位放在空列表
y.append(k.get_text().strip())
data=[x,y]
a=pd.DataFrame(data,index=["目录","职位"])#数据可视化
print("2019年厦门地区职位数据:","\n")#打印
print(a.T)

5.运行结果

猜你喜欢

转载自www.cnblogs.com/w-625/p/12536455.html