python学习-抓取知乎图片
生活随笔
收集整理的這篇文章主要介紹了
python学习-抓取知乎图片
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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 BeautifulSoupdriver = 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")?
posted @ 2019-04-04 15:03 巡山小妖N 閱讀(...) 評論(...) 編輯 收藏
總結
以上是生活随笔為你收集整理的python学习-抓取知乎图片的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python-os创建文件夹-creat
- 下一篇: python学习-Pillow图像处理