国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

python scrapy簡(jiǎn)單模擬登錄的代碼分析

瀏覽:105日期:2022-06-14 18:21:16

1、requests模塊。直接攜帶cookies請(qǐng)求頁面。

找到url,發(fā)送post請(qǐng)求存儲(chǔ)cookie。

2、selenium(瀏覽器自動(dòng)處理cookie)。

找到相應(yīng)的input標(biāo)簽,輸入文本,點(diǎn)擊登錄。

3、scrapy直接帶cookies。

找到url,發(fā)送post請(qǐng)求存儲(chǔ)cookie。

# -*- coding: utf-8 -*-import scrapyimport re class GithubLoginSpider(scrapy.Spider): name = ’github_login’ allowed_domains = [’github.com’] start_urls = [’https://github.com/login’] def parse(self, response): # 發(fā)送Post請(qǐng)求獲取Cookiesauthenticity_token = response.xpath(’//input[@name='authenticity_token']/@value’).extract_first()utf8 = response.xpath(’//input[@name='utf8']/@value’).extract_first()commit = response.xpath(’//input[@name='commit']/@value’).extract_first()form_data = { ’login’: ’pengjunlee@163.com’, ’password’: ’123456’, ’webauthn-support’: ’supported’, ’authenticity_token’: authenticity_token, ’utf8’: utf8, ’commit’: commit}yield scrapy.FormRequest('https://github.com/session', formdata=form_data, callback=self.after_login) def after_login(self, response): # 驗(yàn)證是否請(qǐng)求成功print(re.findall(’Learn Git and GitHub without any code!’, response.body.decode()))

知識(shí)點(diǎn)擴(kuò)展:

parse_login方法是提交完表單后callback回調(diào)函數(shù)指定要執(zhí)行的方法,為了驗(yàn)證是否成功。這里我們直接在response中搜索Welcome Liu這個(gè)字眼就證明登錄成功。

這個(gè)好理解,重點(diǎn)是yield from super().start_resquests(),這個(gè)代表著如果一旦登錄成功后,就直接帶著登錄成功后Cookie值,方法start_urls里面的地址。

這樣的話登錄成功后的response可以直接在parse里面寫。

# -*- coding: utf-8 -*-import scrapyfrom scrapy import FormRequest,Requestclass ExampleLoginSpider(scrapy.Spider): name = 'login_' allowed_domains = ['example.webscraping.com'] start_urls = [’http://example.webscraping.com/user/profile’] login_url = ’http://example.webscraping.com/places/default/user/login’ def parse(self, response):print(response.text) def start_requests(self):yield scrapy.Request(self.login_url,callback=self.login) def login(self,response):formdata = { ’email’:’liushuo@webscraping.com’,’password’:’12345678’}yield FormRequest.from_response(response,formdata=formdata,callback=self.parse_login) def parse_login(self,response):# print(’>>>>>>>>’+response.text)if ’Welcome Liu’ in response.text: yield from super().start_requests()

到此這篇關(guān)于python scrapy簡(jiǎn)單模擬登錄的代碼分析的文章就介紹到這了,更多相關(guān)python scrapy模擬登錄的方法內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: python scrapy requests
主站蜘蛛池模板: 国产美女午夜精品福利视频 | 黑色丝袜美美女被躁视频 | 国产精选一区二区 | 女人精aaaa片一级毛片女女 | 欧美日韩高清不卡免费观看 | 成年人看的黄色片 | 美女张开腿让男人桶爽免 | 日本黄色毛片 | 成人免费网站 | 美女黄色一级片 | 美女视频在线观看黄 | 日本一本久道 | 国产99久久九九精品免费 | 欧美xxxx色视频在线观看 | 久久综合99re久久爱 | 欧美日本韩国一区 | 国内精品一区二区三区最新 | 国产成人精品日本亚洲专 | 永久免费毛片在线播放 | 国产成人精品视频免费 | 欧美激情国内自拍偷 | 成人欧美在线视频 | 免费观看性欧美一级 | 一区二区三区欧美在线 | 亚洲成a人片在线观 | 日韩国产免费 | 国产三香港三韩国三级不卡 | 欧美一级毛片高清免费观看 | 国产三级久久久精品三级 | 欧洲一级大片 | 草草视频在线观看最新 | 日韩乱码中文字幕视频 | 中文字幕乱 | 久久精品国产一区二区 | 欧美一级欧美三级 | 日韩 欧美 中文 亚洲 高清 在线 | 日本大臿亚洲香蕉大片 | 亚洲精品国产第一区第二区国 | 美女个护士一级毛片亚洲 | 午夜免费毛片 | 欧美成人高清在线视频大全 |