在 Chartink.com 上抓取网页

ayu*_*624 4 html python beautifulsoup web-scraping web

请帮我抓取这个链接。链接 - https://chartink.com/screener/time-pass-48 我正在尝试网络抓取,但它没有显示我想要的表格。请同样帮助我。

我已经尝试过这段代码,但它没有给我想要的结果。

import requests
from bs4 import BeautifulSoup

URL = 'https://chartink.com/screener/time-pass-48'
page = requests.get(URL)
print(page)

soup = BeautifulSoup(page.content, 'html.parser')
print(soup)
Run Code Online (Sandbox Code Playgroud)

QHa*_*arr 6

数据确实来自 POST 请求。您不需要允许 JavaScript 运行。您只需要选取一个 cookie(ci_session- 可以使用 Session 对象来保存来自初始登陆页面请求的 cookie 并通过后续 POST 传递)和一个令牌( -可以从初始请求响应中的标签X-CSRF-TOKEN中提取)meta):

import requests
from bs4 import BeautifulSoup as bs
import pandas as pd

data = {
  'scan_clause': '( {cash} ( monthly rsi( 14 ) > 60 and weekly rsi( 14 ) > 60 and latest rsi( 14 ) > 60 and 1 day ago  rsi( 14 ) <= 60 and latest volume > 100000 ) ) '
}

with requests.Session() as s:
    r = s.get('https://chartink.com/screener/time-pass-48')
    soup = bs(r.content, 'lxml')
    s.headers['X-CSRF-TOKEN'] = soup.select_one('[name=csrf-token]')['content']
    r = s.post('https://chartink.com/screener/process', data=data).json()
    #print(r.json())
    df = pd.DataFrame(r['data'])
    print(df)
Run Code Online (Sandbox Code Playgroud)

  • 谢谢先生,非常感谢,但是请告诉我一件事,您的代码显示了筛选器中没有的 33 只额外股票,为什么? (2认同)