中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

諸城做網(wǎng)站的公司php視頻轉碼

諸城做網(wǎng)站的公司,php視頻轉碼,小程序制作卡片列表,物流那個網(wǎng)站做推廣好之前做分布式爬蟲的時候,都是從push url來拿到爬蟲消費的鏈接,這里提出一個問題,假如這個請求是post請求的呢,我觀察了scrapy-redis的源碼,其中spider.py的代碼是這樣寫的 1.scrapy-redis源碼分析 def make_request_from_data(self, data):"""Returns a Reques…

之前做分布式爬蟲的時候,都是從push url來拿到爬蟲消費的鏈接,這里提出一個問題,假如這個請求是post請求的呢,我觀察了scrapy-redis的源碼,其中spider.py的代碼是這樣寫的

1.scrapy-redis源碼分析

    def make_request_from_data(self, data):"""Returns a `Request` instance for data coming from Redis.Overriding this function to support the `json` requested `data` that contains`url` ,`meta` and other optional parameters. `meta` is a nested json which contains sub-data.Along with:After accessing the data, sending the FormRequest with `url`, `meta` and addition `formdata`, `method`For example:.. code:: json{"url": "https://example.com","meta": {"job-id":"123xsd","start-date":"dd/mm/yy",},"url_cookie_key":"fertxsas","method":"POST",}If `url` is empty, return `[]`. So you should verify the `url` in the data.If `method` is empty, the request object will set method to 'GET', optional.If `meta` is empty, the request object will set `meta` to an empty dictionary, optional.This json supported data can be accessed from 'scrapy.spider' through response.'request.url', 'request.meta', 'request.cookies', 'request.method'Parameters----------data : bytesMessage from redis."""formatted_data = bytes_to_str(data, self.redis_encoding)if is_dict(formatted_data):parameter = json.loads(formatted_data)else:self.logger.warning(f"{TextColor.WARNING}WARNING: String request is deprecated, please use JSON data format. "f"Detail information, please check https://github.com/rmax/scrapy-redis#features{TextColor.ENDC}")return FormRequest(formatted_data, dont_filter=True)if parameter.get("url", None) is None:self.logger.warning(f"{TextColor.WARNING}The data from Redis has no url key in push data{TextColor.ENDC}")return []url = parameter.pop("url")method = parameter.pop("method").upper() if "method" in parameter else "GET"metadata = parameter.pop("meta") if "meta" in parameter else {}return FormRequest(url, dont_filter=True, method=method, formdata=parameter, meta=metadata)

源碼地址:https://github.com/rmax/scrapy-redis
可以看到這里是可以處理post請求的

2.scrapy-rabbitmq-schrduler源碼分析

地址:

https://github.com/aox-lei/scrapy-rabbitmq-scheduler

class RabbitSpider(scrapy.Spider):def _make_request(self, mframe, hframe, body):try:request = request_from_dict(pickle.loads(body), self)except Exception as e:body = body.decode()request = scrapy.Request(body, callback=self.parse, dont_filter=True)return request

可以看到RabbitSpider繼承了spider的嘞,改寫了request,當我們發(fā)我post請求的時候?request_from_dict(pickle.loads(body), self)會報錯

builtins.UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

pick.loads 在嘗試反序列化字節(jié)數(shù)據(jù)時遇到無法解碼的字節(jié)序列造成的。具體來說,UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte 說明傳入的數(shù)據(jù)包含非 UTF-8 編碼的字節(jié),可能是二進制數(shù)據(jù)或其他編碼格式的數(shù)據(jù)。

def _make_request(self, mframe, hframe, body):try:# 反序列化 body 數(shù)據(jù)data = pickle.loads(body)# 獲取請求的 URL 和其他參數(shù)url = data.get('url')method = data.get('method', 'GET').upper()  # 默認 GET,如果是 POST 需要設置為 'POST'headers = data.get('headers', {})cookies = data.get('cookies', {})body_data = data.get('body')  # 可能是 POST 請求的表單數(shù)據(jù)callback_str = data.get('callback')  # 回調(diào)函數(shù)名稱(字符串)errback_str = data.get('errback')  # 錯誤回調(diào)函數(shù)名稱(字符串)meta = data.get('meta', {})# 嘗試從全局字典中獲取回調(diào)函數(shù)# 使用爬蟲實例的 `getattr` 方法獲取回調(diào)函數(shù)callback = getattr(self, callback_str, None) if callback_str else Noneerrback = getattr(self, errback_str, None) if errback_str else None# # 確?;卣{(diào)函數(shù)存在# if callback is None:#     self.logger.error(f"Callback function '{callback_str}' not found.")# if errback is None:#     self.logger.error(f"Errback function '{errback_str}' not found.")# 判斷請求方法,如果是 POST,則使用 FormRequestif callback:if method == 'POST':# FormRequest 適用于帶有表單數(shù)據(jù)的 POST 請求request = scrapy.FormRequest(url=url,method='POST',headers=headers,cookies=cookies,body=body_data,  # 請求的主體callback=callback,errback=errback,meta=meta,dont_filter=True)else:# 默認處理 GET 請求request = scrapy.Request(url=url,headers=headers,cookies=cookies,callback=callback,errback=errback,meta=meta,dont_filter=True)else: passexcept Exception as e:body = body.decode()request = scrapy.Request(body, callback=self.parse, dont_filter=True)return request

直接獲取callback是個字符串而不是函數(shù),要在spider中獲取到對應的函數(shù)

注:由于scrapy-rabbitmq-scheduler無人更新維護,目前新的scrapy已經(jīng)不支持,上述最新的代碼已推github:https://github.com/tieyongjie/scrapy-rabbitmq-task

安裝直接安裝

pip install scrapy-rabbitmq-task


?

http://www.risenshineclean.com/news/53964.html

相關文章:

  • 在線直播網(wǎng)站怎么做人民網(wǎng)輿情數(shù)據(jù)中心官網(wǎng)
  • 國外大型網(wǎng)站曹操seo博客
  • 酒泉做網(wǎng)站網(wǎng)站目錄結構
  • 門戶網(wǎng)站建設工作方案在線優(yōu)化seo
  • 深圳市建設科技促進中心網(wǎng)站網(wǎng)絡優(yōu)化網(wǎng)站
  • 做網(wǎng)站的例子設計網(wǎng)站官網(wǎng)
  • 佛山門戶網(wǎng)站建設廣告優(yōu)化師怎么學
  • 做日語字幕的網(wǎng)站杭州關鍵詞排名系統(tǒng)
  • 做vi的網(wǎng)站廣告門
  • 廣告設計圖片 門頭windows優(yōu)化大師有用嗎
  • 零度業(yè)務網(wǎng)站seo學校培訓班
  • 自己做網(wǎng)站要買域名嗎谷歌seo網(wǎng)站推廣怎么做
  • 網(wǎng)站用微信登錄 要怎么做東莞網(wǎng)站優(yōu)化關鍵詞排名
  • 鄭州企業(yè)網(wǎng)站開發(fā)信陽seo推廣
  • 南寧網(wǎng)站設計推廣在線網(wǎng)頁服務器
  • 正能量網(wǎng)站推薦免費下載名詞解釋seo
  • 網(wǎng)站做的圖上傳后字變得很模糊win7一鍵優(yōu)化工具
  • 上海成品網(wǎng)站google推廣一年的費用
  • 沈營商環(huán)境建設監(jiān)督局網(wǎng)站網(wǎng)站開發(fā)的公司
  • 移動網(wǎng)站設計方案好的競價推廣托管
  • 網(wǎng)站做301好不好百度app下載安裝官方免費版
  • 做網(wǎng)站如何避免侵權網(wǎng)絡營銷的重要性
  • 蘇州做網(wǎng)站多少錢廣告投放平臺系統(tǒng)
  • 購買域名需要注意什么seo關鍵詞選取工具
  • 網(wǎng)站關于我們怎么做網(wǎng)絡營銷策劃需要包括哪些內(nèi)容
  • 程序開發(fā)外包平臺公司百度官網(wǎng)優(yōu)化
  • 做全球視頻網(wǎng)站賺錢嗎英文網(wǎng)站推廣
  • 公司名字大全及寓意seo排名首頁
  • iOS開發(fā) 隱私政策網(wǎng)站怎么做軟文發(fā)稿公司
  • 華藝網(wǎng)絡網(wǎng)站開發(fā)手機網(wǎng)站自助建站系統(tǒng)