Javascript 如何渲染JS为cookie生成指纹?

Javascript 如何渲染JS为cookie生成指纹?,javascript,python,cookies,puppeteer,python-requests-html,Javascript,Python,Cookies,Puppeteer,Python Requests Html,本网站使用JS设置cookie 如何运行JS模拟为浏览器以避免429错误 来自请求\u html导入HTMLSession 将HTMLSession()作为s: url='1〕https://www.realestate.com.au/auction-results/nsw' r=s.get(url) 打印(r.状态\ U代码) 打印(右文本) r、 html.render() 打印(右文本) 如果没有某种形式的浏览器模拟,几乎不可能绕过指纹(即使使用seleniumm,我也必须设置一些选项)。

本网站使用JS设置cookie

如何运行JS模拟为浏览器以避免429错误

来自请求\u html导入HTMLSession
将HTMLSession()作为s:
url='1〕https://www.realestate.com.au/auction-results/nsw'
r=s.get(url)
打印(r.状态\ U代码)
打印(右文本)
r、 html.render()
打印(右文本)

如果没有某种形式的浏览器模拟,几乎不可能绕过指纹(即使使用seleniumm,我也必须设置一些选项)。下面是我使用Selenium获得请求所需的唯一关键信息(一个名为“FGJK”的cookie),该信息在随后的请求头中发送,并异步获取所有结果页面

from requests_html import AsyncHTMLSession
import asyncio
from selenium import webdriver
import nest_asyncio

#I'm using IPython which doesn't like async unless the following is applied:
nest_asyncio.apply()

async def get_token():
    options = webdriver.ChromeOptions()
    options.add_experimental_option('excludeSwitches', ['enable-automation']) 
    driver = webdriver.Chrome(options=options)
    driver.get('https://www.realestate.com.au/auction-results/nsw')
    cookies = driver.get_cookies()
    while True:
        for cookie in cookies:
            if cookie['name'] == 'FGJK':
               token = cookie['value'] 
               return token         
            else:
                cookies = driver.get_cookies()


async def get_results(s, endpoint, headers):
    r = await s.get(f'https://www.realestate.com.au/auction-results/{endpoint}', headers=headers)
    #do something with r.html
    print(r, endpoint)


async def main():
    token = await get_token()
    s = AsyncHTMLSession()
    headers = {'Cookie': f'FGJK={token}',
               'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'}    

    r = await s.get(f'https://sales-events-api.realestate.com.au/sales-events/nsw')
    suburbs = r.json()['data']['suburbResults']
    endpoints = [burb['suburb']['urlValue'] for burb in suburbs]    
    asyncio.gather(*(get_results(s, endpoint, headers) for endpoint in endpoints))


asyncio.run(main()) 

您如何找到
sales events api
?我在本地计算机上运行您的代码,并从while循环打印
cookies
。cookie中没有
FGJK
。在多次使用
driver.get_cookies()
之后,您如何抓取
FGJK
?实际上,目前对
sale events api
没有任何保护。如果您能够找到他们的api,那么肯定比使用Selenium抓取cookie更好。我在加拿大,所以我不完全确定FGJK是否只在我这边,但在Firefox、Chrome和Explorer中测试时,我得到了相同的cookie,在每个请求中都必须发送。