try:
self.browser.get(request.url)
if page > 1:
print(page)
# input = self.wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '# J_bottomPage > span.p-skip > input')))
# input.clear()
# input.send_keys(page)
# time.sleep(5)
'''
模拟点击下一页
'''
# fp_next = self.browser.find_element_by_xpath('//*[@id = "J_bottomPage"]/span[1]/a[9]/em')
# # fp_next = browser.find_element_by_css_selector('a.fp-next')
# # 点击下一页
# fp_next.click()
# 将网页中输入跳转页的输入框赋值给input变量 EC.presence_of_element_located,判断输入框已经被加载出来
#input = self.wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '# J_bottomPage > span.p-skip > input')))
input = self.browser.find_element_by_css_selector('span.p-skip input')
input.clear()
input.send_keys(page)
print('成功输入页码')
print('************************')
# 将网页中调准页面的确定按钮赋值给submit变量,EC.element_to_be_clickable 判断此按钮是可点击的
#submit = self.wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '# J_bottomPage > span.p-skip > a')))
submit = self.browser.find_element_by_css_selector('span.p-skip a')
submit.click() # 点击按钮
time.sleep(5)
print('成功点击下一页')
print('************************')
time.sleep(15)
# 判断当前页码出现在了输入的页面中,EC.text_to_be_present_in_element 判断元素在指定字符串中出现
#self.wait.until(EC.text_to_be_present_in_element((By.CSS_SELECTOR, '#J_bottomPage > span.p-num > a.curr'),str(page)))
# 等待 #J_goodsList 加载出来,为页面数据,加载出来之后,在返回网页源代码
#self.wait.until(EC.text_to_be_present_in_element((By.CSS_SELECTOR, '#J_bottomPage > span.p-num > a.curr'),str(page)))
print(request.url)
return HtmlResponse(url=request.url, body=self.browser.page_source, request=request, encoding='utf-8',status=200)
except TimeoutException:
return HtmlResponse(url=request.url, status=500, request=request)