【问题标题】:(Python selenium)Getting past Steam's age check(Python selenium)通过 Steam 的年龄检查
【发布时间】:2021-03-30 23:46:52
【问题描述】:

我是程序和网络抓取的新手。我想编写一个程序来访问一些最畅销的游戏并提取评论内容,但是当它试图访问 M 级游戏时,我的程序只是被重定向到年龄检查页面。 因此,我使用 selenium 单击一些按钮,以便通过年龄检查。

这是一个例子:

IDlist = ['730','1085660']
chrome = webdriver.Chrome('./chromedriver')
for i in IDlist:
    url = 'https://steamcommunity.com/app/%s/reviews/?l=english&browsefilter=toprated&snr=1_5_100010_' %i
    chrome.get(url)

    #the age check page                   
    chrome.find_element_by_css_selector('#ViewAllForApp').click()
    chrome.find_element_by_css_selector('#age_gate_btn_continue').click()                                    
    
    for x in range(1,5):
        chrome.execute_script('window.scrollTo(0,document.body.scrollHeight);')
        time.sleep(2)    
    soup = BeautifulSoup(chrome.page_source, 'html.parser')
       .
       .
       .

第一个游戏 (ID=730) 可以运行,但问题是当我访问第二个游戏 (ID=1085660) 时,它没有年龄检查页面和以下错误消息:

NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#ViewAllForApp"}
  (Session info: chrome=87.0.4280.88)

如何避免这个问题? if-else? 或者尝试其他方法通过年龄检查?(例如添加cookies

【问题讨论】:

    标签: python selenium selenium-webdriver web-scraping beautifulsoup


    【解决方案1】:

    查看 Steam 的年龄检查,您应该可以设置 cookie

    lastagecheckage1-0-1900 path=/;

    birthtime-2211667760 path=/;

    wants_mature_content1 在应用程序的路径,或 /

    在访问商店页面之前,或在初始化您使用的任何 HTTP 库时,有效地绕过年龄检查重定向。

    不要忽视路径,它们很重要。不设置它们可能会导致您进入无限重定向循环。

    用于测试:

    document.cookie = "wants_mature_content=1"; 
    document.cookie = "lastagecheckage=1-0-1900; path=/"; 
    document.cookie = "birthtime=-2211667760; path=/";
    

    在浏览器的 JavaScript 控制台中,例如 https://store.steampowered.com/app/271590/ (GTA V)

    您可以尝试使用lastagecheckagebirthtime cookie,方法是进入隐身模式并查看应用程序中的 cookie,或在有年龄限制的标题上的调试环境中查看网络选项卡。不过,这些应该可以工作。

    【讨论】:

      猜你喜欢
      • 2016-02-09
      • 2019-09-17
      • 1970-01-01
      • 2021-06-29
      • 1970-01-01
      • 2011-05-15
      • 1970-01-01
      • 2013-06-20
      • 2015-05-22
      相关资源
      最近更新 更多