資源簡介
多線程下載網(wǎng)站圖片
代碼片段和文件信息
#python2.7?打造多線程網(wǎng)絡(luò)爬蟲
#庫:threading??安裝lxmlrequestsbs4(beautifulsoup?4)
#?-*-?coding:utf-8?-*-
import?requeststhreading#多線程
from?lxml?import?etree#解析方式
from?bs4?import?BeautifulSoup
#獲取源碼
def?get_html(url):
#url=‘https://www.doutula.com/article/list/?page=1‘
headers={‘User-Agent‘:‘Mozilla/5.0?(Windows?NT?6.1;?WOW64)?AppleWebKit/537.36?(KHTML?like?Gecko)?Chrome/53.0.2785.104?Safari/537.36?Core/1.53.2595.400?QQBrowser/9.6.10872.400‘}
request=requests.get(url=urlheaders=headers)
response=request.content#獲取源碼
#print?response
return?response
#找到圖片的超鏈接獲取源碼
#獲取外頁??獲取超鏈接
def?get_img_html(html):
soup=BeautifulSoup(html‘lxml‘)#解析網(wǎng)頁方式自帶html.parser
all_a=soup.find_all(‘a(chǎn)‘class_=‘list-group-item‘)#找到a標(biāo)簽
for?i?in?all_a:#i是鏈接
img_html=get_html(i[‘href‘])#獲取超鏈接源碼
g
- 上一篇:爬取網(wǎng)站信息并寫入Excel
- 下一篇:python 微信機器人 源碼
評論
共有 條評論