1、抽象的访问并读取某个网页
抽象的访问并读取某个网页,使用爬虫技术的时候需要使用到,所以这里记录一下:
import urllib3
http = urllib3.PoolManager(num_pools=5, headers={'User-Agent': 'ABCDE'})
resp1 = http.request('GET', 'https://blog.csdn.net/wy313622821/article/details/108472125')
# print(resp1.data.decode())#读取网页内容
2、用指定浏览器访问某个网页
方式1(推荐使用):
import webbrowser
IEPath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
webbrowser.register('IE', None, webbrowser.BackgroundBrowser(IEPath))
webbrowser.get('IE').open('https://blog.csdn.net/wy313622821/article/details/108637745', new=1,autoraise=True)
注意:IEPath 换成你个人的浏览器地址
方式2:
import os
os.system('"C:\Program Files\internet explorer\iexplore.exe" https://blog.csdn.net/wy313622821/article/details/108637745')#使用IE打开(第一个参数为浏览器路径,可以改为其他浏览器的路径)
方式3:使用默认浏览器打开某个网页
import webbrowser
webbrowser.open_new_tab('https://blog.csdn.net/wy313622821/article/details/108637745')
方式4:使用默认浏览器打开某个网页
import webbrowser
webbrowser.open("https://blog.csdn.net/wy313622821/article/details/108637745")