私信  •  关注

Alex Kosh

Alex Kosh 最近创建的主题
Alex Kosh 最近回复了
3 年前
回复了 Alex Kosh 创建的主题 » python AsyncHTMLSession:您没有访问此服务器上“XXX”的权限

我认为这是某种机器人检测。然而 requests_html 可以呈现JS,它不是真正的浏览器,不能完全绕过机器人保护。

你可以使用一些库来控制真正的浏览器,比如 playwright / selenium / puppeteer

下面是一个例子 剧作家 :

from playwright.sync_api import sync_playwright

URL = 'https://www.otcmarkets.com'

with sync_playwright() as p:
    # Webkit is fastest to start and hardest to detect
    browser = p.webkit.launch(headless=True)

    page = browser.new_page()
    page.goto(URL)

    html = page.content()

print(html)
3 年前
回复了 Alex Kosh 创建的主题 » 使用Python中的itertools将不同硬币命名的组合汇总为目标值

你需要使用 combinations 而不是 combinations_with_replacement 所以你的 count 支票可以省略。

另外,为什么只检查长度为8的组合?你应该查一下 0 len(all_coins) 这就是为什么 应该有嵌套的for循环 (请参阅所有可能组合的更多示例。) here )

最终代码可能是:

import itertools

ones = [1, 1, 1]  # 3 coins of 1
twos = [2, 2]     # 2 coins of 2
fives = [5, 5, 5] # 3 coins of 5
target = 3

all_coins = ones + twos + fives

res = set()
for coins_to_take in range(len(all_coins)+1):
    for c in itertools.combinations(all_coins, coins_to_take):
        if sum(c) == target:
            res.add(c)

for r in res:
    print(r)