python - 请求 / BeautifulSoup VS robots.txt
问题描述
我试图用一个输入来抓取某个网站。现在我已经用 Scrapy 构建了它,它工作得很好,经过所有的调整(包括不遵守 robots.txt),并且它自动循环运行以进行数据挖掘。
现在我需要做一些可以通过输入刮掉单个页面的东西
问题是,我唯一能够访问的页面是 robots.txt 页面,而且我无法在网上找到任何关于在 robots.txt 周围的信息。
有没有关于如何使用 BS 或 Requests 的教程?
解决方案
尝试传递这些标头,您将获得预期的输出。
import requests
headers = { 'accept':'*/*',
'accept-encoding':'gzip, deflate, br',
'accept-language':'en-GB,en;q=0.9,en-US;q=0.8,hi;q=0.7,la;q=0.6',
'cache-control':'no-cache',
'dnt':'1',
'pragma':'no-cache',
'referer':'https',
'sec-fetch-mode':'no-cors',
'sec-fetch-site':'cross-site',
'user-agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
}
URL = "https://www.crunchbase.com/login"
response = requests.get(url=URL, headers=headers)
print(response.text)
希望这可以帮助!
推荐阅读
- c# - 按 OR 条件分组的有效方法
- javascript - 从 C# 到 Javascript 的 HMAC256 返回不同的结果
- python - 使用 python selenium 从 iframe 内的列表中选择元素
- python - 从 Discord-Client 读取消息不会触发事件
- firebase - 每次我从 Firebase Cloud Messaging 发送通知时,我的应用程序都会崩溃
- amazon-web-services - 从 s3 存储桶恢复到 sql server 出现错误 数据库备份/恢复选项未启用
- javascript - 动态创建的时间选择器字段未触发事件
- python-3.x - 需要有关在 PyTorch 中迁移学习更快的 RCNN ResNet50FPN 的帮助
- session - 生成 20000 个令牌后未显示 ZAP 会话分析对话框
- d3.js - 如何确定一个点是否隐藏在 3D 散点图 (Plotly.js) 上?