爬虫

#!/usr/bin/env python
#-*-coding:utf-8-*-
from bs4 import BeautifulSoup
import requests


headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'
}
for i in range(1,3):
    link = "https://search.51job.com/list/080200,000000,0000,01,9,99,python,2,{}.html?".format(i)
    resp = requests.get(link,headers=headers)
    resp = resp.text
    resp = resp.encode( "ISO-8859-1")
    soup = BeautifulSoup(resp,"lxml")
    names = soup.select(".el p.t1 span a" )
    countrys = soup.select(".el span.t2 a")
    salarys = soup.select(".el span.t4")
    print("=" * 40)
    for index in range(0,len(names)):
        name = names[index]
        country = countrys[index]
        salary = salarys[index+1]
        name = name.text.strip()
        country = country.text.strip()
        salary = salary.text.strip()

        print("名称是:{}".format(name))
        print("公司是:{}".format(country))
        print("薪水是:{}".format(salary))
        print("="*40)
    print("第{}页数据爬取完毕....".format(i))






你可能感兴趣的:(爬虫)