python 批量爬取网页pdf_爬取网页文件并批量解析pdf

很多时候我们需要爬取网上的文件并提取文件的数据做对比,文件一般为pdf格式需要转化为excel表格,现在可以用python实现采集数据到提取数据的全流程操作。

一、首先要爬取网页内容下载pdf文件

import requests

from lxml import html

etree = html.etree

import os

import time

def main(i):

#第一页

if i==1:

url = "http://www.innocom.gov.cn/gxjsqyrdw/gswj/list.shtml"

#进行翻页处理

else:

url = 'http://www.innocom.gov.cn/gxjsqyrdw/gswj/list'+'_'+str(i)+'.shtml'

html = requests.get(url)

time.sleep(60)

xhtml = etree.HTML(html.content.decode("utf-8"))

#定位到需要提取的内容

node = xhtml.xpath('/html/body/div[2]/div[1]/div[3]/ul/li/a[contains(text(), "拟认定")]/@href')

res = []

for url in node:

#拼接pdf的url

url = 'http://www.innocom.gov.cn/' + url

你可能感兴趣的:(python,批量爬取网页pdf)