|
|
发表于 2019-8-27 17:23:57
|
显示全部楼层
本帖最后由 Stubborn 于 2019-8-27 17:26 编辑
- # 获取当前句柄和切换到新的网页窗口
- num = self.driver.window_handles
- self.driver.switch_to.window(num[1])
- # 判断网页是否存在7天热门文章
- response_text = self.driver.page_source
- result = re.findall(r'(.*?)7天热门', response_text, flags=re.S)
- # 存在则写入
- if result:
- response = re.findall(r'<!.*?====文章===.*?-->(.*?)<!-- 询购', response_text, flags=re.S)[0]
- response = "{% extends 'base.html' %}\n{% block content %}\n"+response+"\n{% endblock %}"
- get_html = SeleniunXinbang.get_font_file_path(frequency)
- with open(get_html, 'a',encoding='utf-8') as f:
- f.write(response) # bytes(response, encoding='utf-8')
- # 切换回原来窗口
- self.driver.close()
- self.driver.switch_to.window(num[0])
复制代码
https://fishc.com.cn/forum.php?m ... 43368&ctid=1467 |
|