스파이더에 셀레늄을 배치하십시오
예를 들어, eBay에서 Paginated Results를 긁어냅니다. 다음 스 니펫은 셀레늄을 스크레이프와 통합하는 방법을 보여줍니다. 셀레늄 수입 웹 드라이버에서 클래스 ProductsPider (scrapy.spider) : 이름 = "product_spider" allud_domains = start_urls =
/a') 노력하다: 다음 .click () # 여기에서 데이터를 얻고 처리하십시오 제외하고: 부서지다 self.driver.close()import scrapy from selenium import webdriver class ProductSpider(scrapy.Spider): name = "product_spider" allowed_domains = ['ebay.com'] start_urls = ['https://www.ebay.com/sch/i.html?_odkw=books&_osacat=0&_trksid=p2045573.m570.l1313.TR0.TRC0.Xpython&_nkw=python&_sacat=0&_from=R40'] def __init__(self): self.driver = webdriver.Firefox() def parse(self, response): self.driver.get(response.url) while True: next = self.driver.find_element_by_xpath('//td[@class="pagn-next"]/a') try: next.click() # Get and process the data here except: break self.driver.close()
In some cases, using the ScrapyJS middleware may be sufficient to handle dynamic portions of a webpage without requiring Selenium. 이 미들웨어는 스크레이프 프레임 워크 내에서 사용자 정의 자바 스크립트를 실행할 수 있습니다.
부인 성명: 제공된 모든 리소스는 부분적으로 인터넷에서 가져온 것입니다. 귀하의 저작권이나 기타 권리 및 이익이 침해된 경우 자세한 이유를 설명하고 저작권 또는 권리 및 이익에 대한 증거를 제공한 후 이메일([email protected])로 보내주십시오. 최대한 빨리 처리해 드리겠습니다.
Copyright© 2022 湘ICP备2022001581号-3