BeautifulSoup网页具有保护功能,并且prettify()不返回任何数据

时间:2018-06-21 08:42:26

标签: python beautifulsoup

我正在尝试从葡萄酒网站获取一些数据。

但是我无法评估数据,并且有使用违规消息。

网址:https://www.wine-searcher.com/find/drc/2013

prettify()结果如下:

<div id="bodycontainer">
<div class="colmask contentparent">
 <div id="colheader">
  <div class="colmask articlecontainer">
   <div class="colmidtemp3">
    <div class="collefttemp3">
     <div class="col1wraptemp3">
      <div class="col1temp3">
       <div>
        <h1 style="margin:50px 0 0">
         Usage Violation
        </h1>
        <div style="margin-bottom:50px;padding:50px 10px;background-color:#FFFACD">
         <h2 style="font-size:1.4em">
          Blocked
         </h2>
         <p style="font-size:1.2em">
          The IP Address [xx.xxx.xxx.xx] you are using has been used in violation of Wine-Searcher's usage guidelines.
          <b>
           If you think you have received this message in error restart your web browser and retry accessing wine-searcher.com.
          </b>
         </p>
         <p style="font-size:1.2em">
          To re-gain access to Wine-Searcher please
          <a href="mailto:wsexcessiveuse@wine-searcher.com?subject=Blocked IP=1 ID=PVBXC7PJCM80025">
           Contact Us
          </a>
          .
         </p>
        </div>
       </div>
      </div>
     </div>

是否有任何可能的方法来从URL获取数据?非常感谢。

我的编码在这里:

# -*- coding: utf-8 -*-
import bs4
import re
import requests
import sys
from bs4 import BeautifulSoup

name = "Wine.txt"
k = open(name, "w", encoding='utf-8')

Stat_url = "https://www.wine-searcher.com/find/drc/2012"
page = requests.get(Stat_url)
soup = bs4.BeautifulSoup(page.text,'lxml')

k.write(soup.prettify())

1 个答案:

答案 0 :(得分:0)

似乎他们在页面上添加了一些保护措施,以防止您尝试执行此操作;) 他们通过API https://www.wine-searcher.com/api.lml出售访问权限,并允许在5天内进行100次试用。也许这对您来说足够了?

我想BeautifulSoup会在短时间内尝试许多请求? (也许将其限制为每10秒一次,让它运行一整夜?) 可以将BS中的agent-id更改为更常见的名称,例如常规浏览器的agent-id吗?