python学习-抓取知乎图片

#!/bin/usr/env python3

__author__ = 'nxz'

"""
抓取知乎图片
webdriver Chromedriver驱动需要安装,并指定driver位置(不同chrome版本需要不同的驱动)
""" import re # 正则 from selenium import webdriver # 模拟登陆 import time import urllib.request from bs4 import BeautifulSoup driver = webdriver.Chrome("E:\python插件\chromedriver.exe") driver.maximize_window() driver.get("https://www.zhihu.com/question/29134042") result_raw = BeautifulSoup(open('test.html', encoding='utf-8'), 'lxml') content_list = result_raw.select("noscript") for content in content_list: result = BeautifulSoup(content.string,'lxml') imgs = result.select('img') for img in imgs: with open('img.txt', 'a', encoding='utf-8') as f: f.write(img['src'] + '\n') print("fetch --->>> end")

猜你喜欢

转载自www.cnblogs.com/nxzblogs/p/10654930.html