和xun基金排名爬取

编程入门 行业动态 更新时间:2024-10-12 12:27:25

和xun<a href=https://www.elefans.com/category/jswz/34/1761851.html style=基金排名爬取"/>

和xun基金排名爬取

大约到200多页的时候,出现了反爬

from selenium import webdriver
from selenium.webdrivermon.by import By
from selenium.webdrivermon.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import time
from bs4 import BeautifulSoup
import pymongo
import datetimeclass heshunSpider(object):client =pymongo.MongoClient(host="127.0.0.1", port=27017)db = client.hexun.hxdef __init__(self):self.driver = webdriver.Firefox()def __del__(self):self.driver.close()def run(self):self.driver.maximize_window()self.driver.get(".aspx")time.sleep(1)page = 0while page<399:time.sleep(6)html = self.driver.page_sourcesoup = BeautifulSoup(html,'lxml')time.sleep(1)tr_list = soup.select('.tab01>table>tbody>tr')for tr in tr_list:item = {}item['xuhao'] = tr.find_all("td")[1].stringitem['code'] = tr.find_all("td")[2].find("a").stringitem['name'] = tr.find_all("td")[3].find("a").stringitem['date'] = tr.find_all("td")[4].get_text()item['onem'] = tr.find_all("td")[5].stringitem['threem'] = tr.find_all("td")[6].stringitem['sixm'] = tr.find_all("td")[7].stringitem['oney'] = tr.find_all("td")[8].stringitem['twoy'] = tr.find_all("td")[9].stringitem['threey'] = tr.find_all("td")[10].stringitem['todayy'] = tr.find_all("td")[11].stringitem['create'] = tr.find_all("td")[12].stringitem['rate'] = tr.find_all("td")[13].stringself.db.insert_one(item)# print(item)self.driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")page = page+1self.driver.find_element_by_class_name('next').click()if __name__ == "__main__":spider = heshunSpider()spider.run()

存入mongodb

注:我是个大菜鸟,恳求大神指正,让我进步!

更多推荐

和xun基金排名爬取

本文发布于:2024-02-06 13:02:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1748779.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:基金   xun

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!