def collect_notice(stock_info): req_url = company_accouncement.format(stock_info.stock_number) notice_list_html = send_request(req_url) notice_list_soup = BeautifulSoup(notice_list_html, 'lxml') notice_list = notice_list_soup.find('div', class_='cont').find_all('li') for i in notice_list: notice_title = i.find('span', class_='title').text notice_cate = i.find('span', class_='cate').text notice_date_str = i.find('span', class_='date').text notice_date = datetime.datetime.strptime(notice_date_str, '%Y-%m-%d') notice_url = eastmoney_data + i.find('a').get('href') if not check_duplicate(notice_title, notice_cate, notice_date): notice_html = send_request(notice_url) notice_soup = BeautifulSoup(notice_html, 'lxml') notice_content = notice_soup.find('pre').text stock_notice = StockNotice(stock_number=stock_info.stock_number, stock_name=stock_info.stock_name, notice_title=notice_title, notice_cate=notice_cate, notice_date=notice_date, notice_url=notice_url, notice_content=notice_content) stock_notice.save() time.sleep(random.random())
def collect_notice(stock_number, stock_name): req_url = company_accouncement.format(stock_number) notice_list_html = send_request(req_url) notice_list_soup = BeautifulSoup(notice_list_html, "lxml") notice_list = notice_list_soup.find("div", class_="cont").find_all("li") for i in notice_list: notice_title = i.find("span", class_="title").text notice_cate = i.find("span", class_="cate").text notice_date_str = i.find("span", class_="date").text notice_date = datetime.datetime.strptime(notice_date_str, "%Y-%m-%d") notice_url = eastmoney_data + i.find("a").get("href") if not check_duplicate(notice_title, notice_cate, notice_date): notice_html = send_request(notice_url) notice_soup = BeautifulSoup(notice_html, "lxml") notice_content = notice_soup.find("pre").text stock_notice = StockNotice( stock_number=stock_number, stock_name=stock_name, notice_title=notice_title, notice_cate=notice_cate, notice_date=notice_date, notice_url=notice_url, notice_content=notice_content, ) stock_notice.save() time.sleep(random.random())
def collect_notice(stock_info): req_url = company_notice.format(stock_info.stock_number) raw_data = send_request(req_url).replace('var', '').replace('=', '').replace(';', '').strip() notice_data = json.loads(raw_data).get('data', []) for n in notice_data: notice_title = n.get('NOTICETITLE') notice_code = n.get('INFOCODE') notice_date = datetime.datetime.strptime(n.get('NOTICEDATE').split('T')[0], '%Y-%m-%d') notice_url = single_notice.format(stock_info.stock_number, notice_code) if not is_exists(notice_code): stock_notice = StockNotice(title=notice_title, code=notice_code, date=notice_date, content_url=notice_url, stock_number=stock_info.stock_number, stock_name=stock_info.stock_name) stock_notice.save()
def collect_notice(stock_info): req_url = company_notice.format(stock_info.stock_number) raw_data = send_request(req_url).replace('var', '').replace('=', '').replace( ';', '').strip() notice_data = json.loads(raw_data).get('data', []) for n in notice_data: notice_title = n.get('NOTICETITLE') notice_code = n.get('INFOCODE') notice_date = datetime.datetime.strptime( n.get('NOTICEDATE').split('T')[0], '%Y-%m-%d') notice_url = single_notice.format(stock_info.stock_number, notice_code) if not is_exists(notice_code): stock_notice = StockNotice(title=notice_title, code=notice_code, date=notice_date, content_url=notice_url, stock_number=stock_info.stock_number, stock_name=stock_info.stock_name) stock_notice.save()