91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 3KB
    文件類型: .py
    金幣: 1
    下載: 1 次
    發布日期: 2021-06-13
  • 語言: Python
  • 標簽: python??爬蟲??

資源簡介

用python爬取網絡資源圖片,學習的小例子。網絡爬蟲案例

資源截圖

代碼片段和文件信息

#coding=utf-8
import?requests
from?bs4?import?BeautifulSoup
import?os

all_url?=?‘http://www.mzitu.com‘


#http請求頭
Hostreferer?=?{
????‘User-Agent‘:‘Mozilla/4.0?(compatible;?MSIE?6.0;?Windows?NT?5.1)‘
????‘Referer‘:‘http://www.mzitu.com‘
????}
Picreferer?=?{
????‘User-Agent‘:‘Mozilla/4.0?(compatible;?MSIE?6.0;?Windows?NT?5.1)‘
????‘Referer‘:‘http://i.meizitu.net‘
}
#此請求頭破解盜鏈

start_html?=?requests.get(all_urlheaders?=?Hostreferer)

#保存地址
path?=?‘picture/‘

#找尋最大頁數
soup?=?BeautifulSoup(start_html.text“html.parser“)
page?=?soup.find_all(‘a‘class_=‘page-numbers‘)
max_page?=?page[-2].text


same_url?=?‘http://www.mzitu.com/page/‘
for?n?in?range(1int(max_page)+1):
????ul?=?same_url+str(n)
????start_html?=?requests.get(ul?headers?=?Hostreferer)
????soup?=?BeautifulSoup(start_html.text“html.parser“)
????all_a?=?soup.find(‘div‘class_=‘postlist‘).find_all(‘a‘target=‘_blank‘)
????for?a?in?all_a:
????????title?=?a.get_text()?#提取文本
????????if(title?!=?‘‘):
????????????print(“準備扒取:“+title)
???????????
????????????#win不能創建帶?的目錄
????????????if(os.path.exists(path+title.strip().replace(‘?‘‘‘))):
????????????????#print(‘目錄已存在‘)
????????????????flag=1
????????????else:
????????????????os.makedirs(path?+?title.s

評論

共有 條評論