小编byt*_*776的帖子

雅虎财经python上的某些股票和页面出现404错误

我正在尝试通过此 URL https://finance.yahoo.com/quote/AAPL/key-statistics?p=AAPL从雅虎财经中抓取数据。运行下面的python代码后,我得到以下HTML响应

import numpy as np
import pandas as pd
from bs4 import BeautifulSoup
import requests, lxml
from lxml import html

stockStatDict = {}
stockSymbol = 'AAPL'
URL = 'https://finance.yahoo.com/quote/'+ stockSymbol + '/key-statistics?p=' + stockSymbol
page = requests.get(URL)
print(page.text)


<!DOCTYPE html>
  <html lang="en-us"><head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <meta charset="utf-8">
      <title>Yahoo</title>
      <meta name="viewport" content="width=device-width,initial-scale=1,minimal-ui">
      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
      <style>
  html {
      height: 100%;
  }
  body {
      background: #fafafc url(https://s.yimg.com/nn/img/sad-panda-201402200631.png) 50% 50%;
      background-size: cover;
      height: 100%;
      text-align: center;
      font: 300 18px …
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup web-scraping http-status-code-404

1
推荐指数
1
解决办法
1234
查看次数