[英]BeautifulSoup webpage have protection and prettify() return no data
我想从葡萄酒网站上获取一些数据。
但我无法评估数据,并且存在使用违规消息。
网址: https : //www.wine-searcher.com/find/drc/2013
美化()结果是这样的:
<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>
有没有可能的方法从网址获取数据? 非常感谢。
我的编码在这里:
# -*- 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())
看起来他们为他们的页面添加了一些保护,以防止这种情况,你尝试做什么;)他们通过API https://www.wine-searcher.com/api.lml销售访问权限并允许试用100次调用5天。 也许这对你来说已经足够了?
我猜想BeautifulSoup会在很短的时间内尝试很多请求? (也许将它限制为每10秒钟一次并让它在一夜之间运行?)BS中的agent-id是否可以更改为常规浏览器代理ID更常见的东西?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.