455. Assign Cookies

Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a cookie that the child will be content with; and each cookie j has a size sj. If sj >= gi, we can assign the cookie j to the child i, and the child i will be content. Your goal is to maximize the number of your content children and output the maximum number.


code:

class Solution(object):
    def findContentChildren(self, g, s):
        """
        :type g: List[int]
        :type s: List[int]
        :rtype: int
        """
        l=sorted(g,reverse=True)
        m=sorted(s,reverse=True)
        
        f=0
        for x in l:
            for y in m:
                if x<=y:
                   
                   f+=1
                   m.remove(y)
                   break
              
            
        return f
       

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
是的,如果你想使用requests库维持会话并使用selenium获取的cookie进行请求,请求头应该保持一致。具体来说,你需要将selenium获取的cookie添加到requests的会话中,并且在每个请求中包含与selenium相同的headers。 要获取selenium的headers,你可以使用WebDriver的execute_script方法执行JavaScript代码,获取当前页面的headers。下面是一个示例: ```python from selenium import webdriver # 创建Selenium WebDriver实例 driver = webdriver.Chrome() # 打开一个网页 driver.get("https://example.com") # 执行JavaScript代码来获取headers headers = driver.execute_script("return Object.assign({}, window.navigator, {cookie: document.cookie})") # 打印headers print(headers) # 关闭WebDriver driver.quit() ``` 在这个示例中,我们使用`execute_script`方法执行JavaScript代码来获取当前页面的headers。返回的headers是一个包含cookie和其他navigator属性的字典。 获取了headers后,你可以将其用于requests库的会话中,例如: ```python import requests # 创建requests会话 session = requests.Session() # 设置requests会话的headers和cookies session.headers.update(headers) session.cookies.update(driver.get_cookies()) # 使用requests进行请求 response = session.get("https://example.com") # 打印响应内容 print(response.content) ``` 在这个示例中,我们更新了requests会话的headers和cookies,然后使用requests发送了一个GET请求。 总结起来,如果想要使用selenium获取的cookie,并使用requests库维持会话请求,需要将selenium获取的headers和cookie分别设置到requests会话中的headers和cookies中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值