首页 > 解决方案 > 请求 / BeautifulSoup VS robots.txt

问题描述

我试图用一个输入来抓取某个网站。现在我已经用 Scrapy 构建了它,它工作得很好,经过所有的调整(包括不遵守 robots.txt),并且它自动循环运行以进行数据挖掘。

现在我需要做一些可以通过输入刮掉单个页面的东西

问题是,我唯一能够访问的页面是 robots.txt 页面,而且我无法在网上找到任何关于在 robots.txt 周围的信息。

有没有关于如何使用 BS 或 Requests 的教程?

标签: pythonweb-scrapingbeautifulsoupscrapypython-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)

希望这可以帮助!


推荐阅读