python打开下载好的网页_使用Python打开网页后下载文件

事实上,你所指的是更准确地称之为网站报废,在这种情况下,人们可以从给定的网站上抓取一些特定的内容:Web scraping is a computer software technique of extracting

information from websites. This technique mostly focuses on the

transformation of unstructured data (HTML format) on the web into

structured data (database or spreadsheet).

如果不了解HTML语义,就不可能为您提供所需的代码快照。但在这里我可以给你一些建议,你可以使用一些方法,你可以从你的网站抓取。在

1。非编程方式:For those of you, who need a non-programming way to extract

information out of web pages, you can also look at import.io . It

provides a GUI driven interface to perform all basic web scraping

operations.

2。程序员方式:

您可以找到许多库来使用python执行一个函数。因此,有必要找到最佳的使用库。我更喜欢beauthulsoup,因为它很容易而且直观。确切地说,您使用两个Python模块来获取数据:Urllib2: It is a Python module which can be used for fetching URLs. It defines functions and classes to help with URL actions (basic

and digest authentication, redirections, cookies, etc). For more

detail refer to the documentation page.

BeautifulSoup: It is an incredible tool for pulling out information

from a webpage. You can use it to extract tables, lists, paragraph and

you can also put filters to extract information from web pages. the latest available version is BeautifulSoup 4. You can look

at the installation instruction in its documentation page.

BeautifulSoup无法为我们获取网页。这就是为什么需要将urllib2与beauthoulsoup库结合使用。在

除了BeatifulSoup之外,Python还有其他几个HTML抓取选项。以下是其他一些:

#coding:utf-8 import time import webbrowser as web import os import random #随机选择一个浏览器打开网页 def open_url_use_random_browser(): #定义要访问的地址 url='http://www.baidu.com' #定义浏览器路径 browser_paths=[r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe', #r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe', #r'C:\Program Files (x86)\Opera\launcher.exe', #r'C:\Users\Administrator\AppData\Roaming\qianying\qianying.exe', #r'C:\Users\Administrator\AppData\Local\115Chrome\Application\115chrome.exe', #r'C:\Program Files (x86)\Internet Explorer\iexplore.exe', #r'D:\Program Files(x86)\SouExplorer\SogouExplorer\SogouExplorer.exe' ] #选择一个浏览器 def chose_a_browser_open_url(browser_path,url): #如果传入的浏览器位置不存在,使用默认的浏览器打开 if not browser_path: print ('using default browser to open') web.open_new_tab(url)#使用默认浏览器,就不再结束进程 else: #判断浏览器路径是否存在 if not os.path.exists(browser_path): print ('current browser path not exists,using default browser') #浏览器位置不存在就使用默认的浏览器打开 browser_path='' chose_a_browser_open_url(chose_a_browser_open_url,url) else: browser_task_name=browser_path.split('\\')[-1]#结束任务的名字 browser_name=browser_task_name.split('.')[0]#自定义的浏览器代号 print (browser_name) web.register(browser_name, None,web.BackgroundBrowser(browser_path)) web.get(browser_name).open_new_tab(url)#使用新注册的浏览器打开网页 print ('using %s browser open url successful' % browser_name) time.sleep(5)#等待打开浏览器 # kill_cmd='taskkill /f /IM '+browser_task_name#拼接结束浏览器进程的命令 # os.system(kill_cmd) #终结浏览器 browser_path=random.choice(browser_paths)#随机从浏览器中选择一个路径 chose_a_browser_open_url(browser_path,url) if __name__ == '__main__': print (''''' ***************************************** ** Welcome to python of browser ** ** Created on 2019-04-28 ** ** @author: Louise_ZOU ** ***************************************** ''') open_url_use_random_browser()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值