加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test.py 1.81 KB
一键复制 编辑 原始数据 按行查看 历史
chenxiaoyu 提交于 2021-01-20 23:51 . 第一次提交
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument(
'user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36')
br = webdriver.Chrome(options=chrome_options)
with open('D:/project/stealth/stealth.min.js') as f:
js = f.read()
br.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": js
})
# 打开页面搜索
br.get(
'http://www.iwencai.com/unifiedwap/result?w={}&querytype=stock'.format("陆股通持股比例前100"))
time.sleep(1)
first_search = True
if first_search:
# 翻页
page = br.find_element_by_css_selector(".pcwencai-pagination-wrap>.drop-down-box>.drop-down-arrow")
page.click()
time.sleep(1)
checktext = br.find_elements_by_css_selector(".pcwencai-pagination-wrap>.drop-down-box>div>ul>li")
checktext[-1].click()
time.sleep(5)
first_search = False
start_time = time.time()
# #iwcTableWrapper > div.iwc-table-container > div.iwc-table-content.isTwoLine > div.iwc-table-fixed > div.iwc-table-body-outer > div > table > tbody > tr:nth-child(37) > td:nth-child(4)
result = br.find_elements_by_css_selector(
"#iwcTableWrapper > div.iwc-table-container > div.iwc-table-content.isTwoLine > div.iwc-table-scroll > div.iwc-table-body > table > tbody > tr > td > div")
tableData = []
end_time=time.time()
print("所花费时间{}", (end_time - start_time))
index = 0
for i in range(100):
row = [result[i*15].text, result[i*15+2].text,
result[i*15+3].text, result[i*15+4].text,
result[i*15+6].text, result[i*15+9].text]
tableData.append(row)
end_time = time.time()
print("所花费时间{}", (end_time - start_time))
br.close()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化