python简易爬取今日头条的热榜 | 您所在的位置:网站首页 › 河北今日新闻最新头条10条内容图片 › python简易爬取今日头条的热榜 |
前言 提到python就离不开爬虫,把想要的资料文章新闻图片视频等等都获取到并保存,百度上随便找个网站就能练练但是爬取的东西都没啥意义,好玩的网站反爬机制小白破解不了流程也复杂,接口入参加密长时间调接口ip被限制等等,但是selenium是最无敌的,走到哪几乎就能获取到哪,闲的没事写写玩 今日头条首页的头条热榜【换一批】 代码 先是把启动selenium单拿出来写 from selenium import webdriver import time class Ui: def __init__(self): self.url = 'https://www.toutiao.com/' def Supply_chain(self): options = webdriver.ChromeOptions() options.add_experimental_option('excludeSwitches',['enable-logging']) #关闭打印日志 # options.add_argument('--headless') #关闭浏览器头(无头模式) test = webdriver.Chrome('drive\chromedriver.exe',options=options) test.get(self.url) test.maximize_window() time.sleep(4) return test然后在另一个模块中引用这个Supply_chain方法,进行业务操作获取到保存就行了,每次都会创建文件夹名字用的uuid防止重复 from common.open_headlines import Ui import xlsxwriter import uuid |
CopyRight 2018-2019 实验室设备网 版权所有 |