seleium模拟爬取天眼查

前言

seleium模拟爬取天眼查网站公司的评分,基本信息,法律诉讼,行政处罚等信息

Release 1.0

自动滑块暂未实现

from selenium import webdriver
import time
import csv
import requests
from bs4 import BeautifulSoup
driver = webdriver.Chrome(executable_path='C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe')
driver.maximize_window()
driver.get("https://www.tianyancha.com")
driver.implicitly_wait(10)
driver.find_element_by_css_selector("#web-content > div > div.tyc-home-top.bgtyc > div.mt-74 > div > div > div.right > div > div:nth-child(4) > a").click()
driver.implicitly_wait(10)

#自动登录
driver.find_element_by_xpath("//*[@class='title-tab text-center']/div[2]").click()
driver.find_element_by_xpath("//*[@class='modulein modulein1 mobile_box  f-base collapse in']/div[2]//*[@class='input contactphone']").clear()
driver.find_element_by_xpath("//*[@class='modulein modulein1 mobile_box  f-base collapse in']/div[2]//*[@class='input contactphone']").send_keys("yourCounr")
time.sleep(2)
driver.find_element_by_xpath("//*[@class='modulein modulein1 mobile_box  f-base collapse in']/div[3]//*[@class='input contactword input-pwd']").clear()
driver.find_element_by_xpath("//*[@class='modulein modulein1 mobile_box  f-base collapse in']/div[3]//*[@class='input contactword input-pwd']").send_keys("yourPassword")
time.sleep(1)
driver.find_element_by_xpath("//*[@class='modulein modulein1 mobile_box  f-base collapse in']/div[5]").click()
time.sleep(4)

#模拟移动滑块

#print(driver.title)
def str():
    start_url = "https://www.tianyancha.com/search?key=%s"
    csv_reader = csv.reader(open('e.csv', encoding='utf8'))
    for row in csv_reader:
        url = start_url % row[0]
        driver.get(url)
        amount=driver.find_element_by_class_name("score ").text
        write_csv(amount)

        print(amount)
        #html=requests.get(url).text
        #soup=BeautifulSoup(html,"lxml")
        #data=soup.find(
            #'div',attrs={'class': 'score '}).find("span")
        #print(data)
        time.sleep(2)
def write_csv(amount):
    with open("e_score.csv","a+",newline='',encoding="utf-8") as f:
        writer = csv.writer(f,delimiter='\t')
        writer.writerow(amount)

if __name__ == '__main__':
    str()

driver.quit()
driver.close()
《分分合合好,cvcxc 数据库开发 交互 平面/illustrator
哈克力摩托车手们快来加入一下这个游戏小剧场哦啦啦啦
已标记关键词 清除标记
实付 39.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值