파충류 잡기 51job 소프트웨어 테스트 페이지에서 모 회사 이름python 구현
9614 단어 파충류
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°reefrom=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°reefrom=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)
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
python은 어떻게 파충류의 효율을 향상시킬 것인가단일 스레드 + 멀티태스킹 비동기 협동 협정 함수(특수 함수)를 정의할 때 async 수식을 사용합니다. 함수 호출 후 내부 문장은 즉시 실행되지 않고 협동 대상으로 되돌아옵니다. 퀘스트 대상 작업 대상 = 고급 협...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.