Python爬取网站用户手机号_设计师的福利,python爬取素材网站
生活随笔
收集整理的這篇文章主要介紹了
Python爬取网站用户手机号_设计师的福利,python爬取素材网站
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
前言
本文的文字及圖片來源于網(wǎng)絡(luò),僅供學(xué)習(xí)、交流使用,不具有任何商業(yè)用途,如有問題請及時聯(lián)系我們以作處理。
基本環(huán)境配置
- python 3.6
- pycharm
- requests
- parsel
相關(guān)模塊pip安裝即可
確定網(wǎng)站目標(biāo)
基本常規(guī)操作,F12打開開發(fā)者工具,分析網(wǎng)頁
網(wǎng)頁返回的數(shù)據(jù) ,都是一堆亂碼,再寫代碼的時候可以轉(zhuǎn)一下編碼就好了
靜態(tài)網(wǎng)頁都是非常簡單的,是可以直接抓取到自己想要的數(shù)據(jù)的
請求網(wǎng)頁
import requestsimport reurl = 'http://www.sccnn.com/shiliangtuku/default({}).html'.format(page)headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'}response = requests.get(url=url, headers=headers)response.encoding = response.apparent_encoding分析網(wǎng)頁,解析數(shù)據(jù)
import parselr = re.findall('', response.text)urls = r[2:]for i in urls: page_url = 'http://www.sccnn.com' + i response_2 = requests.get(url=page_url, headers=headers) response_2.encoding = response_2.apparent_encoding selector = parsel.Selector(response_2.text) title = selector.css('#LeftBox h2::text').get() img_url = selector.css('#LeftBox .PhotoDiv img::attr(src)').get()保存數(shù)據(jù)
def downlaod(title, url): path = 'D:pythondemo素材網(wǎng)站img' + title + '.jpg' response = requests.get(url=url, headers=headers) with open(path, mode='wb') as f: f.write(response.content) print('正在下載{}'.format(title))實(shí)現(xiàn)效果
完整項目代碼后臺私信小編01獲取!
總結(jié)
以上是生活随笔為你收集整理的Python爬取网站用户手机号_设计师的福利,python爬取素材网站的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何判断数组所有数都不等于一个数_【每日
- 下一篇: api怎么写_月薪几十K 的人是怎么设计