python 個人爬蟲實戰

2021-09-24 13:20:50 字數 1638 閱讀 7913

from bs4 import beautifulsoup

from urllib import request

import pandas as pd

import time

from datetime import datetime

head={}

#如需使用cookie登入,將cookie位址傳入head即可

#如: "host":"ts.21cn.com",

"connection": "keep-alive",

"accept":" */*",

"accept-encoding": "gzip, deflate, br",

"accept-language": "zh-cn,zh;q=0.9",

"referer": "",

"cookie":"你的cookie位址,按f12在network》xhr》cookie" }

"""jts_url_list=

for i in range(1,11):

output=pd.dataframe()

for jts_url in jts_url_list:

jts_req=request.request(url=jts_url,headers=head)

jts_respon=request.urlopen(jts_req)

jts_html=jts_respon.read().decode('utf-8','ignore')

jts_dict=eval(jts_html)

jts_ctime_list=

jts_id_list=

jts_picture_list=

jts_title_list=

jts_shorttopic_list=

jts_shuqiu_list=

jts_tail_url_list=

output2=pd.dataframe()

for jts_url_num in range(10):

output2 = pd.dataframe()

output=pd.concat([output,output2],ignore_index=true)

time.sleep(2)

print(str(jts_url)+"完成")

def stamp_to_datetime(stamp):

"""將時間戳(1539100800)轉換為 datetime2018-10-09 16:00:00格式並返回

:param stamp:

:return:

"""time_stamp_array = datetime.utcfromtimestamp(stamp)

date_time = time_stamp_array.strftime("%y-%m-%d %h:%m:%s")

# 如果直接返回 date_time則為字串格式2018-10-09 16:00:00

date = datetime.strptime(date_time,"%y-%m-%d %h:%m:%s")

return date

output.to_excel(r'爬蟲結果.xlsx',index=false)

python爬蟲實戰

python python基礎 python快速教程 python學習路線圖 python大資料學習之路 python爬蟲實戰 python pandas技巧系 量化小講堂 python機器學習入門資料梳理 學習群 大資料 python資料探勘2 323876621 r r語言知識體系 怎樣學習r ...

Python爬蟲實戰(二)

實驗介紹 本實驗通過使用beautifulsoup方法對網頁進行簡單的爬取工作,並對beatifulsoup方法進行簡單的介紹。beautifulsoup開發手冊 示例網頁如下 實驗內容 從本地網頁爬取商品資訊,商品名,評分等級等相關資訊 實驗 from bs4 import beautifulso...

Python爬蟲實戰2 0

這次實戰的內容是非同步載入 非同步載入和普通的數字下表迭代的url不同的地方在於不能直接通過乙個for迴圈來獲取每乙個頁面的內容。如何判別翻頁是否是非同步載入的呢?開啟瀏覽器檢查,然後定位到頁面內容的那部分html 然後在瀏覽器按下翻頁按鈕,如果發現html 部分內容閃了一下,那麼說明網頁是通過非同...