【问题标题】:Any option to bypass Incapsula protection in python3 while scraping?抓取时绕过python3中的Incapsula保护的任何选项?
【发布时间】:2019-10-03 17:54:48
【问题描述】:

我是爬虫新手,我已经被 Incapsula 保护挡住了。

import bs4
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup

my_url = 'https://www.immoweb.be/fr/recherche/immeuble-de-rapport/a-vendre'

# opening up connection, grabbing the page
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()

#html parsing
page_soup = soup(page_html, "html.parser")

page_soup.h1 

我无法从网站访问任何数据,因为我被 InCapsula 问题阻止...
当我输入时:

print(page_soup)

我收到这条消息:

<html style="height:100%"><head><meta content="NOINDEX, NOFOLLOW" name="ROBOTS"/><meta content="telephone=no" name="format-detection"/>
[...]
Request unsuccessful. Incapsula incident ID: 936002200207012991-

【问题讨论】:

标签: python web-scraping beautifulsoup incapsula


【解决方案1】:

我做了一些这里描述的测试 Getting ‘wrong’ page source when calling url from python 并且只有 @Karl Anka 的解决方法解决了。

请看下面的例子:

from bs4 import BeautifulSoup
from selenium import webdriver

url = 'https://www.immoweb.be/fr/recherche/immeuble-de-rapport/a-vendre'

driver = webdriver.Chrome(executable_path='./chromedriver')
driver.get(url)

soup = BeautifulSoup(driver.page_source, features='html.parser')
driver.quit()

print(soup.prettify())

输出:

<html class="js flexbox rgba borderradius boxshadow opacity cssgradients csstransitions generatedcontent localstorage sessionstorage" style="" xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://opengraphprotocol.org/schema/">
 <head>
  <script async="" src="https://c.pebblemedia.be/js/data/david/_david_publishers_master_produpress.js" type="text/javascript">
  </script>
  <script async="" src="https://scdn.cxense.com/cx.js" type="text/javascript">
  </script>
  <script async="" src="https://connect.facebook.net/signals/plugins/inferredEvents.js?v=2.8.47">
  </script>
  <script async="" src="https://connect.facebook.net/signals/config/1554445828209863?v=2.8.47&amp;r=stable">
  </script>
[...]

【讨论】:

  • 感谢您的帮助!我得到了和你一样的输出。现在我需要学习如何从页面中的不同房地产属性中提取不同的信息。
  • 问题是,目前最好的办法是使用 Selenium 和 Fake_agent 绕过封装
  • 同时尝试使用代理和 selenium。 InCapsula 也使用浏览器指纹识别技术
猜你喜欢
  • 1970-01-01
  • 2018-09-19
  • 1970-01-01
  • 2020-11-04
  • 2020-09-22
  • 1970-01-01
  • 1970-01-01
  • 2021-07-24
  • 2016-01-19
相关资源
最近更新 更多