【问题标题】:Webscraping the Indian Patent Website for patent data在印度专利网站上搜索专利数据
【发布时间】: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


【解决方案1】:

您只需 请求 即可完成此操作。该帖子是 http://ipindiaservices.gov.in/publicsearch/resources/webservices/search.php 和一个 param rc_ 这是我们用 time.time 创建的时间戳.

"field[]" 中的每个值都应与"fieldvalue[]" 中的每个值匹配,然后再匹配"operator[]",无论您选择*AND* *OR* 还是*NOT*,每个键后的[] 指定我们正在传递一个 value(s) 数组,没有它什么都不会工作。:

data = {
    "publication_type_published": "on",
    "publication_type_granted": "on",
    "fieldDate": "APD",
    "datefieldfrom": "19120101",
    "datefieldto": "20160906",
    "operatordate": " AND ",
    "field[]": ["PA"], # claims,.description, patent-number codes go here
    "fieldvalue[]": ["chris*"], # matching values for ^^ go here
    "operator[]": [" AND "], # matching sql logic for ^^ goes here
    "page": "1", #  gives you next page results
    "start": "0", # not sure what effect this actually has.
    "limit": "25"} # not sure how this relates as  len(r.json()[u'record']) stays 25 regardless

import requests
from time import time

post = "http://ipindiaservices.gov.in/publicsearch/resources/webservices/search.php?_dc={}".format(
    str(time()).replace(".", ""))

with requests.Session() as s:
    s.get("http://ipindiaservices.gov.in/publicsearch/")
    s.headers.update({"X-Requested-With": "XMLHttpRequest"})
    r = s.post(post, data=data)
    print(r.json())

输出将如下所示,由于要发布的数据太多,我无法全部添加:

{u'success': True, u'record': [{u'Publication_Status': u'Published', u'appDate': u'2016/06/16', u'pubDate': u'2016/08/31', u'title': u'ACTUATOR FOR DEPLOYABLE IMPLANT', u'sourceID': u'inpat', u'abstract': u'\n    Systems and methods are provided for usin.............

如果你使用记录键,你会得到一个像这样的字典列表:

{u'Publication_Status': u'Published', u'appDate': u'2015/01/27', u'pubDate': u'2015/06/26', u'title': u'CORRUGATED PALLET', u'sourceID': u'inpat', u'abstract': u'\n    A corrugated paperboard pallet is produced from two flat blanks which comprise a pallet top and a pallet bottom. The two blanks are each folded to produce only two parallel vertically extending double thickness ribs&nbsp;three horizontal panels&nbsp;two vertical side walls and two horizontal flaps. The ribs of the pallet top and pallet bottom lock each other from opening in the center of the pallet by intersecting perpendicularly with notches in the ribs. The horizontal flaps lock the ribs from opening at the edges of the pallet by intersecting perpendicularly with notches&nbsp;and the vertical sidewalls include vertical flaps that open inward defining fork passages whereby the vertical flaps lock said horizontal flaps from opening.\n  ', u'Assignee': u'OLVEY Douglas A., SKETO James L., GUMBERT Sean G., DANKO Joseph J., GABRYS Christopher W., ', u'field_of_invention': u'FI10', u'publication_no': u'26/2015', u'patent_no': u'', u'application_no': u'642/DELNP/2015', u'UCID': u'WVJ4NVVIYzFLcUQvVnJsZGczcVRmSS96Vkh3NWsrS1h3Qk43S2xHczJ2WT0%3D', u'Publication_Type': u'A'}

这是您的专利信息。

你可以看到如果我们在浏览器中选择了几个值,所有fieldvaluefieldoperator中的值都排成一行,@ 987654336@是默认值,因此您可以看到每个选项:

所以找出代码,选择你想要的并发布。

【讨论】:

  • 这太棒了!谢谢。我将编写代码,然后用它做更多的事情。非常感谢。
  • 不用担心,只需选择您想要的任何值,确保列表中的对齐并发布到 url,您将获得所需的 json 格式。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-24
  • 1970-01-01
  • 1970-01-01
  • 2013-02-08
  • 2013-05-04
  • 2017-09-12
  • 1970-01-01
相关资源
最近更新 更多