日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

抽屉网

發布時間:2023/12/20 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 抽屉网 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

==========================(一)=========================

# -*- coding: utf-8 -*-
import scrapy
class ChoutiSpider(scrapy.Spider):
? ? name = 'chouti'
? ? allowed_domains = ['chouti.com']
? ? start_urls = ['http://dig.chouti.com/']


? ? # def start_requests(self):
? ? #? ? ?print('//')


? ? # 第一次請求之后返回的響應
? ? # 有的網站在返回登錄頁面時,會攜帶一些登錄需要的參數,例如csrf_token,xsrf等等,需要先從登錄頁面中提取所需參數,再發送POST請求
? ? def parse(self, response):
? ? ? ? '''
? ? ? ? 通過發送POST請求,模擬登錄
? ? ? ? response 可以從response中提取一些登錄需要參數
? ? ? ? '''
? ? ? ? # 重新發起一次POST登錄請求
? ? ? ? # FormRequest() 是scrapy提供的用于發送POST請求的類
? ? ? ? yield scrapy.FormRequest(
? ? ? ? ? ? # 登錄地址
? ? ? ? ? ? url='http://dig.chouti.com/login',
? ? ? ? ? ? # 請求參數
? ? ? ? ? ? formdata={
? ? ? ? ? ? ? ? 'phone':'8615237034401',
? ? ? ? ? ? ? ? 'password':'13243259989',
? ? ? ? ? ? ? ? 'oneMonth':'1'
? ? ? ? ? ? },
? ? ? ? ? ? # 回調函數
? ? ? ? ? ? callback=self.parse_index
? ? ? ? )
? ? def parse_index(self, response):
? ? ? ? '''
? ? ? ? {"result":{"code":"9999", "message":"", "data":{"complateReg":"0","destJid":"cdu_52091364220"}}}
? ? ? ? '''
? ? ? ? print(response.text)
? ? ? ? print('...')
? ? ? ? yield scrapy.Request(
? ? ? ? ? ? url='http://dig.chouti.com/user/link/saved/1',
? ? ? ? ? ? callback=self.parse_index
? ? ? ? )



=======================(二)==================================

# -*- coding: utf-8 -*-
import scrapy
import codecs
import requests
class Chouti2Spider(scrapy.Spider):
? ? name = 'chouti2'
? ? allowed_domains = ['chouti.com']


? ? # start_urls 可以不用設置
? ? # start_urls = ['http://dig.chouti.com/']


? ? # 整個爬蟲程序第一個調用的函數,第一個請求就是從這發出去的,
? ? def start_requests(self):


? ? ? ? # for循環遍歷start_urls,根據取出url創建request對象,yield request對象


? ? ? ? # 發送登錄的POST請求
? ? ? ? yield scrapy.FormRequest(
? ? ? ? ? ? url='http://dig.chouti.com/login',
? ? ? ? ? ? formdata={
? ? ? ? ? ? ? ? 'phone':'8615237034401',
? ? ? ? ? ? ? ? 'password':'13243259989',
? ? ? ? ? ? ? ? 'oneMonth':'1'
? ? ? ? ? ? },
? ? ? ? ? ? # callback如果不指定,回調parse()函數
? ? ? ? ? ? # callback=self.parse
? ? ? ? ? ? headers={
? ? ? ? ? ? ? ? 'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0'
? ? ? ? ? ? }
? ? ? ? )


? ? def parse(self, response):
? ? ? ? # 取出cookies
? ? ? ? headers = response.headers.iteritems()
? ? ? ? for x in headers:
? ? ? ? ? ? if b'Set-Cookie' in x:
? ? ? ? ? ? ? ? cookies = x[1]
? ? ? ? ? ? ? ? cookies = [ck.decode('utf-8').split(';')[0] for ck in cookies]
? ? ? ? ? ? ? ? cookie_str = ';'.join(cookies[:2])


? ? ? ? # 直接訪問登錄后才能訪問頁面
? ? ? ? yield scrapy.Request(
? ? ? ? ? ? url='http://dig.chouti.com/user/link/saved/1',
? ? ? ? ? ? callback=self.parse_center,
? ? ? ? ? ? headers={
? ? ? ? ? ? ? ? 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0',
? ? ? ? ? ? ? ? 'Host':'dig.chouti.com',
? ? ? ? ? ? ? ? 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
? ? ? ? ? ? ? ? 'Referer':'http://dig.chouti.com/',
? ? ? ? ? ? ? ? 'Connection':'keep-alive',
? ? ? ? ? ? ? ? 'Cookie':cookie_str,# gpsd 這個cookie有問題
? ? ? ? ? ? ? ? 'Upgrade-Insecure-Requests':'1'
? ? ? ? ? ? }
? ? ? ? )
? ? def parse_center(self, response):
? ? ? ? print(response.text)
? ? ? ? with codecs.open('1.html','w+',encoding='utf-8') as f:
? ? ? ? ? ? f.write(response.text)








'd217b0e9ece60ada35f57015f54e8f59'
'd217b0e9ece60ada35f57015f54e8f59'
'd217b0e9ece60ada35f57015f54e8f59'













總結

以上是生活随笔為你收集整理的抽屉网的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。