xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

  • 大小: 0.26M
    文件類型: .zip
    金幣: 2
    下載: 1 次
    發(fā)布日期: 2021-06-06
  • 語言: Python
  • 標簽: 其他??

資源簡介

python檢索新浪微博.zip

資源截圖

代碼片段和文件信息

#?coding:?utf-8

import?urllib.request
import?time
import?random
from?lxml?import?etree
import?logging
import?xlrd
from?xlutils.copy?import?copy

#?導入所需模塊
import?urllib.error
import?urllib.request
import?urllib.parse
import?re
import?rsa
import?http.cookiejar??#?從前的cookielib
import?base64
import?json
import?urllib
import?binascii

class?CollectData():
????“““數(shù)據(jù)收集類
???????利用微博高級搜索功能,按關(guān)鍵字搜集一定時間范圍內(nèi)的微博。
????“““

????def?__init__(self?keyword?area?startTime?interval=‘50‘fileS=“weibo.csv“flag=True?begin_url_per=“http://s.weibo.com/weibo/“):
????????self.begin_url_per?=?begin_url_per??#?設置固定地址部分
????????self.setKeyword(keyword)??#?設置關(guān)鍵字
????????self.setArea(area)??#?設置關(guān)鍵字
????????self.setStartTimescope(startTime)??#?設置搜索的開始時間
????????#?self.setRegion(region)??#設置搜索區(qū)域
????????self.setInterval(interval)??#?設置鄰近網(wǎng)頁請求之間的基礎(chǔ)時間間隔(注意:過于頻繁會被認為是機器人)
????????self.setFileS(fileS)??#?設置鄰近網(wǎng)頁請求之間的基礎(chǔ)時間間隔(注意:過于頻繁會被認為是機器人)
????????self.setFlag(flag)

????#設置關(guān)鍵字
????#關(guān)鍵字需解碼后編碼為utf-8
????def?setKeyword(self?keyword):
????????self.keyword?=?keyword.encode(“utf-8“)

????def?setArea(self?area):
????????self.area?=?area

????def?setFileS(self?fileS):
????????self.fileS?=?fileS

????def?getKeyWord(self):
????????return?urllib.parse.quote(self.keyword)

????def?getArea(self):
????????return?self.area

????????##設置起始范圍,間隔為1天

????#格式為:yyyy-mm-dd
????def?setStartTimescope(self?startTime):
????????if?not?(startTime?==?‘-‘):
????????????self.timescope?=?startTime
????????else:
????????????self.timescope?=?‘-‘

????##設置鄰近網(wǎng)頁請求之間的基礎(chǔ)時間間隔
????def?setInterval(self?interval):
????????self.interval?=?int(interval)

????????def?setInterval(self?interval):
????????????self.interval?=?int(interval)

????#設置是否被認為機器人的標志。
????def?setFlag(self?flag):
????????self.flag?=?flag

????#構(gòu)建URL
????def?getURL(self):
????????return?self.begin_url_per?+?“?q=“?+?self.getKeyWord()?+?“®ion=custom:“?+?self.getArea()?+?“&scope=ori&suball=1×cope=custom:“?+?self.timescope?+?“&Refer=g&page=“

????????##爬取一次請求中的所有網(wǎng)頁,最多返回50頁

????def?download(self?url?maxTryNum=4):
????????hasMore?=?True??#?某次請求可能少于50頁,設置標記,判斷是否還有下一頁
????????isCaught?=?False??#?某次請求被認為是機器人,設置標記,判斷是否被抓住。抓住后,需要,進入頁面,輸入驗證碼

????????i?=?1??#?記錄本次請求所返回的頁數(shù)
????????while?hasMore?and?i?????????????source_url?=?url?+?str(i)??#?構(gòu)建某頁的URL
????????????data?=?‘‘??#?存儲該頁的網(wǎng)頁數(shù)據(jù)
????????????goon?=?True??#?網(wǎng)絡中斷標記
????????????##網(wǎng)絡不好的情況,試著嘗試請求三次
????????????for?tryNum?in?range(maxTryNum):
????????????????try:
????????????????????html?=?urllib.request.urlopen(source_url?timeout=12)
????????????????????data?=?html.read().decode()
????????????????????break
????????????????except:
????????????????????if?tryNum?????????????????????????time.sleep(10)
????????????????????else:
????????????????????????print(‘Internet?Connect?Error!‘)
????????????????????????self.flag?=?False
???????????

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-03-16?13:06??python檢索新浪微博\
?????文件??????267829??2019-03-15?13:26??python檢索新浪微博\readme.docx
?????文件???????59392??2019-03-15?13:15??python檢索新浪微博\weiboData.xls
?????文件????????8287??2019-03-16?13:02??python檢索新浪微博\xinLang.py

評論

共有 條評論