You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.5 KiB
45 lines
1.5 KiB
import random
|
|
import re
|
|
|
|
import requests
|
|
|
|
from .user_agents_pool import agent_list
|
|
|
|
cookies = {
|
|
'v': 'A5DYFny5wkcml55DX08-YhOpYdXnWXSjlj3Ip4phXOu-xT7LMmlEM-ZNmCbZ',
|
|
}
|
|
|
|
headers = {
|
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
|
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
|
'Cache-Control': 'no-cache',
|
|
'Connection': 'keep-alive',
|
|
# 'Cookie': 'v=A5DYFny5wkcml55DX08-YhOpYdXnWXSjlj3Ip4phXOu-xT7LMmlEM-ZNmCbZ',
|
|
'Pragma': 'no-cache',
|
|
'Sec-Fetch-Dest': 'document',
|
|
'Sec-Fetch-Mode': 'navigate',
|
|
'Sec-Fetch-Site': 'same-origin',
|
|
'Sec-Fetch-User': '?1',
|
|
'Upgrade-Insecure-Requests': '1',
|
|
'User-Agent': random.choice(agent_list),
|
|
'sec-ch-ua': '"Microsoft Edge";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
|
|
'sec-ch-ua-mobile': '?0',
|
|
'sec-ch-ua-platform': '"Windows"',
|
|
}
|
|
def search_fund_by_id(fund_id):
|
|
response = requests.get(f'https://fund.10jqka.com.cn/{fund_id}/', cookies=cookies, headers=headers)
|
|
html = response.content.decode('utf-8')
|
|
# 编写正则表达式来匹配基金名
|
|
pattern = r'([\u4e00-\u9fa5]+[\u4e00-\u9fa5\s]*\([\d]+\))'
|
|
|
|
# 使用 re.search 查找匹配的基金名
|
|
match = re.search(pattern, html)
|
|
|
|
# 提取并打印基金名
|
|
if match:
|
|
fund_name = match.group(1)
|
|
print("基金名:", fund_name)
|
|
return fund_name
|
|
else:
|
|
return None
|
|
# search_fund_by_id('000001') |