我正在尝试抓取以下网站:https://sabobic.blogabet.com
我的爬虫已经抓取了我需要的内容。但在点击"See on“-Button之后,我不知道如何再次启动我的方法"crawltips”。
这是我当前的代码:
class AlltipsSpider(Spider):
name = 'alltips'
allowed_domains = ['blogabet.com']
def start_requests(self):
self.driver = webdriver.Chrome('C:\webdrivers\chromedriver.exe')
# Place all user urls here
url = "https://sabobic.blogabet.com"
self.driver.get(url)
yield scrapy.http.Request (url, callback=self.crawltips)
def crawltips(self, response):
sel = Selector(text=self.driver.page_source)
allposts = sel.xpath('//*[@class="block media _feedPick feed-pick"]')
for post in allposts:
username = post.xpath('.//div[@class="col-sm-7 col-lg-6 no-padding"]/a/@title').extract()
publish_date = post.xpath('.//*[@class="bet-age text-muted"]/text()').extract()
yield{'Username': username,
'Publish date': publish_date
}
try:
self.driver.find_element_by_id('last_item').click()
sleep(5)
except NoSuchElementException:
self.logger.info('No more tipps')
yield Request(url, callback=self.crawltips)我认为收益函数有问题,因为我没有新的url…
发布于 2019-09-22 13:56:12
下面的代码应该可以工作:
yield scrapy.Request(self.driver.current_url,callback=self.crawltips)https://stackoverflow.com/questions/58043807
复制相似问题