【问题标题】:web scraping / web crawling showing 403 error on the site i want to crawl网页抓取/网页抓取在我要抓取的网站上显示 403 错误
【发布时间】:2021-09-30 03:12:11
【问题描述】:
import requests
from bs4 import BeautifulSoup
url ='https://www.vesselfinder.com/vessels'
headers= {'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)'}
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
response.status_code

我尝试了不同的用户代理但仍然无法正常工作,我尝试了其他网站它可以工作但该网站无法正常工作,请帮助我从该网站抓取所有船只数据。提前谢谢!!!

【问题讨论】:

    标签: web-scraping web-crawler python-3.7 http-status-code-403


    【解决方案1】:

    服务器需要额外的语言标头

    import requests
    
    headers = {
        'user-agent': 'Mozilla/5.0',
        'accept-language': 'en-GB,en-US;q=0.9,en;q=0.8',
    }
    
    response = requests.get('https://www.vesselfinder.com/vessels', headers=headers)
    response.status_code
    

    【讨论】:

      猜你喜欢
      • 2020-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多