简体   繁体   English

用户代理问题呈现不可读的标记html源数据

[英]User agent issue renders unreadable tag html source data

Opening the following URL code inspection in Chrome yeilds the following message: 在Chrome中打开以下URL代码检查 ,产生以下消息:

Refused to set unsafe header "User-Agent" 拒绝设置不安全的标题“User-Agent”

And the code behind the site looks like this: 该网站背后的代码如下所示:

<div dir="auto" class="rn-13yce4e rn-fnigne rn-ndvcnb rn-gxnn5r rn-deolkf rn-cme181 rn-1471scf rn-14xgk7a rn-1b43r93 rn-o11vmf rn-ebii48 rn-vw2c0b rn-t9a87b rn-1mnahxq rn-61z16t rn-p1pxzi rn-11wrixw rn-wk8lta rn-9aemit rn-1mdbw0j rn-gy4na3 rn-bauka4 rn-q42fyq rn-qvutc0">24 Count</div>

Opening the same link in Internet Explorer seems to render the tags properly, for example: gbcvs-c-addToCart__inner can be found. 在Internet Explorer中打开相同的链接似乎正确地呈现标记,例如:可以找到gbcvs-c-addToCart__inner。

Selenium is used to read the page, and it used to work with Chrome. Selenium用于阅读页面,它曾用于Chrome。 Is there a way to set the user agent knowing the program will run in Linux? 有没有办法设置用户代理知道程序将在Linux中运行?

I tried the following with no luck.. 我试过以下没有运气..

options = webdriver.ChromeOptions()
options.add_argument('--user-agent="Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko"')

I would like to keep using the chrome driver. 我想继续使用chrome驱动程序。

There is no generic way to do it, but for chrome you can use a plugin like this one to fake your user agent header. 没有通用的方法,但对于chrome,您可以使用像这样的插件伪造您的用户代理标头。 When using chrome from Selenium you can then load that extension and use it to change that header for all requests. 使用Selenium中的chrome时,您可以加载该扩展名并使用它来更改所有请求的标题。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM