這篇文章將為大家詳細(xì)講解有關(guān)動態(tài)網(wǎng)頁用python爬蟲解析的方法,小編覺得挺實(shí)用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
創(chuàng)新互聯(lián)是一家專業(yè)提供富陽企業(yè)網(wǎng)站建設(shè),專注與網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站制作、html5、小程序制作等業(yè)務(wù)。10年已為富陽眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)絡(luò)公司優(yōu)惠進(jìn)行中。
json是一種數(shù)據(jù)存儲格式,可以被多種語言解析,一般用于數(shù)據(jù)傳輸。
data = json.loads(html_str);
all_items=data['topic_list']['topics'] write_content=[];
for item in all_items:
slug = item['slug'];
item_id = item['id']
link = f'https://forum.cocos.org/t/{slug}/{item_id}'
title = item['title'];
like_count = item['like_count'];
like_count = item['like_count'];
posts_count = item['posts_count'];
views = item['views'];
created_at = item['created_at'];
write_content.append({'標(biāo)題': title, '鏈接': link, '點(diǎn)贊':like_count, '回復(fù)':posts_count, '瀏覽':views, '發(fā)帖時間':created_at});其中的鏈接地址可以通過打開幾個論壇內(nèi)容找到規(guī)律,是由 slug 和 id 這兩個字段拼接的。

最后使用多線程 和 csv 存儲結(jié)果。
pool = Pool(3);
orign_num=[x for x in range(0,10)];
result = pool.map(scrapy,orign_num);
with open('ccc_title_link.csv', 'w', newline='') as csvfile:
fieldnames = ('標(biāo)題', '鏈接', '點(diǎn)贊', '回復(fù)','瀏覽', '發(fā)帖時間')
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for write_content in result:
for _content in write_content:
writer.writerow(_content);關(guān)于動態(tài)網(wǎng)頁用python爬蟲解析的方法就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
分享標(biāo)題:動態(tài)網(wǎng)頁用python爬蟲解析的方法
新聞來源:http://chinadenli.net/article36/ggjisg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、移動網(wǎng)站建設(shè)、動態(tài)網(wǎng)站、網(wǎng)站排名、網(wǎng)站制作、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)