【发布时间】:2017-01-14 08:44:21
【问题描述】:
我正在尝试为Indian patent search website 编写一个网络爬虫,以获取有关专利的数据。这是我到目前为止的代码。
#import the necessary modules
import urllib2
#import the beautifulsoup functions to parse the data
from bs4 import BeautifulSoup
#mention the website that you are trying to scrape
patentsite="http://ipindiaservices.gov.in/publicsearch/"
#Query the website and return the html to the variable 'page'
page = urllib2.urlopen(patentsite)
#Parse the html in the 'page' variable, and store it in Beautiful Soup format
soup = BeautifulSoup(page)
print soup
不幸的是,印度专利网站并不健全,或者我不确定如何在这方面进一步推进。
这是上面代码的输出。
<!--
###################################################################
## ##
## ##
## SIDDHAST.COM ##
## ##
## ##
###################################################################
--><!DOCTYPE HTML>
<html>
<head>
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>
<meta charset="utf-8"/>
<title>:: InPASS - Indian Patent Advanced Search System ::</title>
<link href="resources/ipats-all.css" rel="stylesheet"/>
<script src="app.js" type="text/javascript"></script>
<link href="resources/app.css" rel="stylesheet"/>
</head>
<body></body>
</html>
我想给出的是,假设我提供了一个公司名称,抓取工具应该获得该特定公司的所有专利。如果我能把这部分做对,我想做其他事情,比如提供一组输入,刮板将使用它来查找专利。但我被困在无法继续前进的部分。
任何有关如何获取此数据的指针将不胜感激。
【问题讨论】:
-
嗯,你得到了你要求的 html。然而,这个页面似乎是作为一个 web 应用程序制作的,其中所有内容都通过 JavaScript 处理(在
app.js中)。所以你的方法很可能不会奏效。您可能想查看该网站是否提供您可以使用的 API -
是的,我确实在寻找这类信息。那似乎不存在。我也尝试了几个在线网络爬虫。有没有办法,我可以抓取这个网站?
-
正如我所说,它更像是一个网络应用程序而不是一个网站(因为它完全通过 javascript 驱动)。你也许可以使用 Selenium 做一些事情,但我从未使用过它。
-
^如果 Selenium 使用起来太复杂,请使用 Casper.js 或 Phantom.js。
标签: python python-2.7 web-scraping beautifulsoup