前言
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()
哈克力摩托车手们快来加入一下这个游戏小剧场哦啦啦啦