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

您的位置:首頁技術文章
文章詳情頁

python scrapy簡單模擬登錄的代碼分析

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

1、requests模塊。直接攜帶cookies請求頁面。

找到url,發送post請求存儲cookie。

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

找到相應的input標簽,輸入文本,點擊登錄。

3、scrapy直接帶cookies。

找到url,發送post請求存儲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): # 發送Post請求獲取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): # 驗證是否請求成功print(re.findall(’Learn Git and GitHub without any code!’, response.body.decode()))

知識點擴展:

parse_login方法是提交完表單后callback回調函數指定要執行的方法,為了驗證是否成功。這里我們直接在response中搜索Welcome Liu這個字眼就證明登錄成功。

這個好理解,重點是yield from super().start_resquests(),這個代表著如果一旦登錄成功后,就直接帶著登錄成功后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()

到此這篇關于python scrapy簡單模擬登錄的代碼分析的文章就介紹到這了,更多相關python scrapy模擬登錄的方法內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: python scrapy requests
主站蜘蛛池模板: 老司机成人免费精品视频 | 亚洲一区二区精品推荐 | 高清不卡毛片 | 91视频国产精品 | 91精品久久久 | 韩国一级淫片视频免费播放 | 欧美韩国日本一区 | 亚洲男同视频网站 | 久久r这里只有精品 | 久草在线视频网 | 99re9精品视频在线 | 免费一区在线观看 | 狼人激情网| 国产三级在线免费观看 | 国产一级大片免费看 | 久久精品a亚洲国产v高清不卡 | 萌白酱在线喷水福利视频 | 成年人在线观看视频免费 | 国产在线一区二区 | 蕾丝视频永久在线入口香蕉 | 波多野结衣视频免费观看 | 久久久久视频精品网 | 黄色欧美网站 | 免费毛片a| 国产乱码一区二区三区四川人 | 国产亚洲精品看片在线观看 | 波多野结衣中文视频 | 欧美日韩在线观看精品 | 欧美成人极品怡红院tv | 男人天堂男人天堂 | a一级爱做片免费 | 亚洲自偷自拍另类12p | 国产一区二区精品久久凹凸 | 亚洲欧美日韩国产精品影院 | 乱人伦中文视频在线观看免费 | 欧美xxx国产xxx| 国产精品三级手机在线观看 | 欧美国产91 | japanese日本舒服丰满 | 久久国产成人午夜aⅴ影院 久久国产成人亚洲精品影院老金 | 国产日韩精品一区二区在线观看 |