print("正在抓取...") for stk in stocks.symbol: url = "http://vip.stock.finance.sina.com.cn/corp/go.php/vCI_CorpManager/stockid/%s.phtml" % stk html = requests.get(url, headers=headers) html.encoding = 'gb18030' tree = etree.HTML(html.text) name_list = tree.xpath(name_xpath) job_list = tree.xpath(job_xpath) start_list = tree.xpath(start_xpath) end_list = tree.xpath(end_xpath) stock_list = [stk] * len(name_list) name_list = [name.text for name in name_list] job_list = [job.text for job in job_list] start_list = [start.text for start in start_list] end_list = [end.text for end in end_list] all_name.extend(name_list) all_job.extend(job_list) all_start.extend(start_list) all_end.extend(end_list) all_stock.extend(stock_list)
时间: 2024-04-05 17:34:16 浏览: 393
这段代码使用循环遍历stocks列表中的每个股票,然后构造该股票对应的URL地址,并使用requests库发送HTTP请求获取该URL对应的HTML文档。接着使用lxml库的etree模块解析该HTML文档,并使用xpath提取出HTML文档中指定的股票经理信息。然后将每个股票经理的姓名、职位、开始时间和结束时间分别存入到name_list、job_list、start_list和end_list列表中,并将该股票的代码stk复制为一个长度与股票经理数量相同的列表stock_list。最后将name_list、job_list、start_list、end_list和stock_list中的元素分别添加到all_name、all_job、all_start、all_end和all_stock列表中。这样就完成了对所有股票经理信息的抓取和提取。
相关问题
avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x39 avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x39 avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x39 avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x39 avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x39 avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x39 avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x39 avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x39 avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x39 avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x39
这个错误提示通常是由于AVR芯片与编程器之间的通讯问题引起的。可能的原因是:
1. 编程器与计算机连接的USB接口不稳定。
2. 编程器与芯片之间的连接不良。
3. 芯片被损坏或者不支持使用的编程器。
针对这些问题,可以尝试以下解决方法:
1. 确认编程器与计算机连接的USB接口稳定,或者更换USB接口。
2. 检查编程器与芯片之间的连接是否良好,或者更换连接线。
3. 尝试使用另一个芯片进行测试,或者更换支持的编程器。
如果以上方法都无法解决问题,可以尝试在论坛或社区上寻求帮助,或者联系厂家技术支持。
def __stk_surv(): df=pd.read_sql("select ts_code from stock_basic", con = con0) ts_code = (df[df['ts_code'].str.contains('[HZ]')]['ts_code'] .drop_duplicates() .apply(lambda x: f"'{x}'") .reset_index(drop=True)) for i in ts_code: try: start_date = str(pd.read_sql("select surv_date from stk_surv", con = con3).sort_values('surv_date',ascending = False).iloc[0,0]) start_date=pd.to_datetime(start_date)+pd.Timedelta(1,'days') start_date=start_date.strftime('%Y%m%d') except: start_date = 20220101 dateToday = datetime.date.today().strftime('%Y%m%d') end_date = dateToday i = i[1:10] df = pro.stk_surv(**{ "ts_code": i, "trade_date": "", "start_date": start_date, "end_date": end_date, "limit": "", "offset": "" }, fields=[ "ts_code", "name", "surv_date", "fund_visitors", "rece_place", "rece_mode", "rece_org", "org_type", "comp_rece" ]) # print(df) time.sleep(0.31) df = df[df['rece_mode'].str.contains('调研')] df.to_sql(name='stk_surv',con=con3,if_exists='append',index=False) 增加进度条
你可以在循环中使用tqdm库来添加进度条。以下是修改后的代码示例:
```
from tqdm import tqdm
import time
def __stk_surv():
df=pd.read_sql("select ts_code from stock_basic", con = con0)
ts_code = (df[df['ts_code'].str.contains('[HZ]')]['ts_code']
.drop_duplicates()
.apply(lambda x: f"'{x}'")
.reset_index(drop=True))
for i in tqdm(ts_code):
try:
start_date = str(pd.read_sql("select surv_date from stk_surv", con = con3).sort_values('surv_date',ascending = False).iloc[0,0])
start_date=pd.to_datetime(start_date)+pd.Timedelta(1,'days')
start_date=start_date.strftime('%Y%m%d')
except:
start_date = 20220101
dateToday = datetime.date.today().strftime('%Y%m%d')
end_date = dateToday
i = i[1:10]
df = pro.stk_surv(**{
"ts_code": i,
"trade_date": "",
"start_date": start_date,
"end_date": end_date,
"limit": "",
"offset": ""
}, fields=[
"ts_code",
"name",
"surv_date",
"fund_visitors",
"rece_place",
"rece_mode",
"rece_org",
"org_type",
"comp_rece"
])
# print(df)
time.sleep(0.31)
df = df[df['rece_mode'].str.contains('调研')]
df.to_sql(name='stk_surv',con=con3,if_exists='append',index=False)
```
在上面的代码中,我们使用了tqdm库来包装循环,以自动为你添加进度条。你可以根据需要自定义进度条的样式和位置。
阅读全文