import re
import requests
import time
import csv
import random
from lxml import etree
from mouse import move,click
from bs4 import BeautifulSoup
from selenium import webdriver
from pyquery import PyQuery as pq
# from selenium.webdriver.support import expected_conditions as EC
# from selenium.webdriver.support.wait import WebDriverWait
# from selenium.webdriver.common.by import By
# from selenium.webdriver import Chrome, ChromeOptions
# from selenium.webdriver.chrome.options import Options
# from selenium.webdriver.common.keys import Keys
path = '.\chromedriver.exe'
browser = webdriver.Chrome(executable_path=path)
url = 'http://www.cninfo.com.cn/new/fulltextSearch?notautosubmit=&keyWord=%E5%B9%B3%E5%AE%89%E9%93%B6%E8%A1%8C%E4%BE%9B%E5%BA%94%E9%93%BE%E9%87%91%E8%9E%8D'
browser.get(url)
browser.maximize_window()
time.sleep(2)
browser.find_element_by_xpath('//*[@id="tab-1"]').click()
time.sleep(3)
# browser.find_element_by_link_text("南宁市").click()
# time.sleep(3)
source = browser.page_source
tree=etree.HTML(source)
div_list=tree.xpath('//*[@id="fulltext-search"]/div/div/div[2]/div[4]/div[1]/div/div[3]/table//tr')
while len(div_list)==0:
browser.find_element_by_xpath('//*[@id="tab-1"]').click()
time.sleep(3)
source = browser.page_source
tree=etree.HTML(source)
div_list=tree.xpath('//*[@id="fulltext-search"]/div/div/div[2]/div[4]/div[1]/div/div[3]/table//tr')
for div in div_list:
data=[]
id=div.xpath('./td[1]/div/span/text()')[0]
text="".join(div.xpath('./td[2]//text()'))
data.append(id)
data.append(text)
with open('data.csv', 'a', newline='', encoding='utf-8-sig') as fp:
writer = csv.writer(fp)
writer.writerow(data)
browser.find_element_by_xpath('//*[@id="tab-1"]').click()
import csv
import random
from lxml import etree
from mouse import move,click
from bs4 import BeautifulSoup
from selenium import webdriver
from pyquery import PyQuery as pq
import time
import re
# from selenium.webdriver.support import expected_conditions as EC
# from selenium.webdriver.support.wait import WebDriverWait
# from selenium.webdriver.common.by import By
# from selenium.webdriver import Chrome, ChromeOptions
# from selenium.webdriver.chrome.options import Options
# from selenium.webdriver.common.keys import Keys
path = '.\chromedriver.exe'
browser = webdriver.Chrome(executable_path=path)
import pandas as pd
data=pd.read_csv("全部A股12(1).csv",encoding="gbk")
for j in range(0,4439):
id= data.iloc[j]["证券代码"].split(".")[0]
name=data.iloc[j]["证券名称"]+"供应链金融"
num=0
for i in range(1,10):
url = 'http://www.cninfo.com.cn/new/fulltextSearch/full?searchkey={}&sdate=&edate=&isfulltext=true&sortName=nothing&sortType=desc&pageNum={}'.format(name,i)
browser.get(url)
browser.maximize_window()
time.sleep(2)
source = browser.page_source
titles = re.findall(r'"secCode":"(.*?)","secName":"(.*?)","orgId":"(.*?)","announcementId":"(.*?)","announcementTitle":"(.*?)","announcementTime":(.*?),"adjunctUrl":"(.*?)","adjunctSize":(.*?)"announcementContent":"(.*?)","orgName"',source)
for t in titles:
datas=[]
new_id=t[0]
if id==new_id:
times=int(t[6].split("/")[1].split("-")[0])
if times<=2021 and times>=2009:
text=pq(pq(t[4]+t[8]).text()).text()
datas.append(new_id)
datas.append(text)
datas.append(times)
with open('newdata.csv', 'a', newline='', encoding='utf-8-sig') as fp:
writer = csv.writer(fp)
writer.writerow(datas)
print(t)
num=num+1
if num>=15:
break
# self.titles = re.findall(r'target="_blank">(.*?)</a></h2>',self.page)
# for title in self.titles:
|