简体   繁体   English

将casperjs的默认浏览器更改为chrome(更改用户代理字符串)

[英]Change the default browser of casperjs to chrome (Change the user-agent string)

I found out that the default browser of casperjs is safari, because when I tried to access this site https://z1.expertchoice.com using casper and created a screenshot. 我发现casperjs的默认浏览器是safari,因为当我尝试使用casper访问此站点https://z1.expertchoice.com并创建了一个屏幕截图。

How can I change the default browser to chrome? 如何将默认浏览器更改为chrome?

CasperJS doesn't use Safari. CasperJS不使用Safari。 In fact, it can only use PhantomJS and SlimerJS headless browsers for its automation. 事实上,它只能使用PhantomJS和SlimerJS无头浏览器进行自动化。 Therefore, it cannot work with Chrome either. 因此,它也无法与Chrome一起使用。

You are probably hitting a site that does user-agent detection. 您可能正在访问进行用户代理检测的站点。 When a browser makes an HTTP request, it typically includes a request header called User-Agent which contains information used to identify the browser and other technologies and their versions. 当浏览器发出HTTP请求时,它通常包含一个名为User-Agent的请求标头,其中包含用于标识浏览器及其他技术及其版本的信息。 For instance: 例如:

User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36

As you have discovered, you can configure your user-agent string in CasperJS using: 如您所知,您可以使用以下命令在CasperJS中配置用户代理字符串:

casper.userAgent('Your User-Agent String Here');

There are many lists online of well known user-agent strings . 有许多众所周知的用户代理字符串在线列表

create parameters create参数

You can also set it on create : 您也可以在create设置它:

var casper = require('casper').create({
    pageSettings: {
        userAgent: 'mystery browser'
    }
});

If you pass an empty string, you get: User-Agent: Mozilla/5.0 . 如果传递一个空字符串,则会得到: User-Agent: Mozilla/5.0 Which is likely a sensible prefix to your userAgent so that PhantomJS will get better output form websites. 这可能是您的userAgent的合理前缀,因此PhantomJS将从网站获得更好的输出。

You may also be interested in websites which contain common Firefox user agent strings like this one: http://www.useragentstring.com/pages/Firefox/ to make it look like you are a real user. 您可能还对包含常见Firefox用户代理字符串的网站感兴趣,例如: http//www.useragentstring.com/pages/Firefox/ ,使其看起来像您是真正的用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将浏览器用户代理 Header 更改为 javaScript? - How to change browser User-Agent Header with javaScript? 更改 javascript 音频播放器的用户代理 - Change user-agent of javascript audio player 更改音频标签的User-Agent - Change User-Agent of audio tag 如何更改请求标头(用户代理)中的客户端信息? - How to change the client informations in the request header (User-Agent)? 有什么方法可以更改 Apps 脚本的 User-Agent 吗? - Is there any way to change User-Agent of Apps script? 在抓取 Google 搜索时更改设置特定用户代理字符串时,CasperJS 返回不同的结果 - CasperJS returns different results when change setting a specific user agent string when scraping Google search 是否可以使用Chrome欺骗用户代理和操作系统? - Is possible to spoof user-agent and OS with Chrome? 谁能帮助您以编程方式使用Selenium Webdriver将修改标头用户代理添加到Chrome浏览器 - Can anyone help to how to add modify header user-agent to chrome browser using selenium webdriver programmatically HTMLUnit:更改用户代理字符串 - HTMLUnit: change User Agent string 更改Chrome扩展程序的URL用户代理 - Change Chrome Extension User Agent for URL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM