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")
相關文章
相關標籤/搜索