파충류 잡기 51job 소프트웨어 테스트 페이지에서 모 회사 이름python 구현

9614 단어 파충류
#요구사항: 51job 소프트웨어 테스트 페이지에서 모 회사 이름을 캡처하여 부류를 학습하고 호출하는 데 주로 사용
spider1.py
import requests
class spider():
    def __init__(self):
        self.headers={"user-agent":"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"}
    def submit(self,url):
        response=requests.get(url,self.headers)
        response.encoding = "gbk"
        return response.text

if __name__=="__main__":
    obj=spider()
    res=obj.submit("https://www.51job.com")
    print(res)

spider2.py spider2에는 초기화 방법에만 url 파라미터를 추가하여 부류를 호출하는 것을 배우기 위해 사용하고 url을 spider1의 초기화에 직접 쓰는 것이 적합합니다
#51job            ,             
import requests
from Spider.spiderV1 import spider

class spiderV2(spider):
    def __init__(self,url):  #--url   
        self.url2=url         #--self.url2    
        spider.__init__(self)

if __name__=='__main__':
    u="https://search.51job.com/list/080300,000000,0000,00,9,99,%25E8%25BD%25AF%25E4%25BB%25B6%25E6%25B5%258B%25E8%25AF%2595,2,1.html?lang=c&stype=&postchannel=0000&workyear=99&cotype=99&degreefrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare="
    obj=spiderV2(u)      #--u    
    res=obj.submit(obj.url2)     #-- url2      **         /  ,     
    print(res)

spider3.py
import requests
from lxml import etree
from Spider.spiderV2 import spiderV2

class spiderV3(spiderV2):
    def __init__(self):
        spiderV2.__init__(self,u)
    def position(self,spage):
        dic={}
        document=etree.HTML(spage)
        ele=document.xpath('//*[@id="resultList"]/div[4]/span[1]/a/text()')
        dic=['   :',ele]
        return dic
    def savedata(self,d):
        with open("company.txt","w") as file:
            file.write(str(d))

if __name__=="__main__":
    u="https://search.51job.com/list/080300,000000,0000,00,9,99,%25E8%25BD%25AF%25E4%25BB%25B6%25E6%25B5%258B%25E8%25AF%2595,2,1.html?lang=c&stype=&postchannel=0000&workyear=99&cotype=99&degreefrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare="
    obj3=spiderV3()
    obj3.url3=u
    res=obj3.submit(obj3.url3)
    pos=obj3.position(res)
    print(pos)
    obj3.savedata(pos)

좋은 웹페이지 즐겨찾기