简体   繁体   English

由Incapsula保护的网站的网络抓取?

[英]Web scraping for the website which was secured by Incapsula?

I am in need to scrape the data from the website here . 我需要从这里的网站上抓取数据。 This was protected by Incapsula. 这受Incapsula保护。 I have already done two approaches and also used the techniques which were given by Stack Overflow users. 我已经完成了两种方法,还使用了Stack Overflow用户提供的技术。

APPROACH 1 : 方法1

from incapsula import IncapSession

headers = {'Host': 'www.vignanam.org',
           'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/7.0.540.0 Safari/534.10',
           'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
           'Accept-Language': 'en-US,en;q=0.5',
           'Accept-Encoding': 'gzip, deflate',
           'Connection': 'keep-alive',
           'Cookie': 'visid_incap_1642409=B+YoelHCSKKN5z/Phs0zXCsF9VsAAAAAQUIPAAAAAACXaWvcNDXdMzcOky/SvffB; incap_ses'
                     '_715_1642409=kyFvSyJuuBVpNuh+aTHsCSsF9VsAAAAAKV6TIWTPSZmb+mOZWeuNHA==',
           'Upgrade-Insecure-Requests': '1'}

session = IncapSession()
response = session.get('http://www.vignanam.org/index.htm#&panel1-1', headers=headers, bypass_crack=True)

print response.text

APPROACH 2: 方法2:

from mechanize import Browser
from bs4 import BeautifulSoup

browser = Browser()

browser.open('https://www.incapsula.com/blog/how-incapsula-protects-against-data-leaks.html')

print browser.response()

soup = BeautifulSoup(browser.response().read(), features='html5lib')

print soup

Both approaches are producing the same results. 两种方法都产生相同的结果。

RESULT/OUTPUT 结果/输出

<html> 
<head> 
<META NAME="robots" CONTENT="noindex,nofollow"> 
<script src="/_Incapsula_Resource SWJIYLWA=5074a744e2e3d891814e9a2dace20bd4,719d34d31c8e3a6e6fffd425f7e032f3"> </script> 
<body> 
</body>
</html>

How to break this and scrape the data from there? 如何解决这个问题并从那里抓取数据? Is any other programming languages to overcome this? 还有其他编程语言可以克服这个问题吗?

This : 这个 :

import requests

requests.get('http://www.vignanam.org/index.htm#&panel1-1').text

worked fine for me. 对我来说很好。

I didn't see any kind of incapsula protection and it didn't block my request. 我没有看到任何封装保护,也没有阻止我的请求。

( curl http://www.vignanam.org/index.htm#&panel1-1 worked too in bash) curl http://www.vignanam.org/index.htm#&panel1-1在bash中也起作用)

Returns : 返回值:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" itemscope itemtype="http://schema.org/Organization">\n<head>\n<title>Vaidika Vignanam - Vedic Chants, Siva, Vishnu, Devi\nStotrams, Annamayya, Tyagaraja, Ramadasa Keerthanas in Sanskrit, Hindi,\nTelugu, Tamil, Kannada, Malayalam, Gujarati, Bengali and Oriya</title>\n<link rel=stylesheet type="text/css" href="css/vignanam.css"/>\n<link rel=stylesheet href="css/anythingslider.css" type="text/css" media=screen />\n<link type="text/css" href="css/jquery-ui-1.8.12.custom.css" rel=Stylesheet />\n<link rel=stylesheet href=aqtree3clickable.css />\n<link rel=stylesheet href="css/glowtabs.css" type="text/css" media=screen />\n<meta content="text/html; charset=utf-8" http-equiv=Content-Type />\n<meta name=keywords content="vedas, vedic chants, shiva stotrams, vishnu stotrams, \n\t\tdevi ......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM