Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of setting header by Selenium PhantomJs under Python

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "what is the method of setting header in Selenium PhantomJs under Python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Don't say much, just go to the code.

From selenium import webdriverfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilitiesdef getSource (url): headers = {'Accept':' text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3','User-Agent':' Mozilla/5.0 (Windows NT 6.1) WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.4882.400 QQBrowser/9.7.13059.400','referer':' http://www.taobao.com'}# uses copy () to prevent modification of the original code definition dictcap = DesiredCapabilities.PHANTOMJS.copy () for key, value in headers.items (): cap ['phantomjs.page.customHeaders. {}' .format (key)] = value# does not load the picture Page climbing will be much faster cap ["phantomjs.page.settings.loadImages"] = Falsedriver = webdriver.PhantomJS (desired_capabilities=cap) driver.get (encodeUrl (url))

Some blog posts mentioned that this method is used to set up User-Agent, which seems to be possible:

Cap ["phantomjs.page.settings.userAgent"] = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36' "what is the method of setting header in Selenium PhantomJs under Python?" that's it. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report