中英人寿爬虫爬取,使用selenium自动化和正则表达式
来源:互联网 发布:源氏物语 知乎 编辑:程序博客网 时间:2024/04/28 14:32
import reimport requestsfrom bs4 import BeautifulSoupimport pandas as pdimport numpy as npfrom selenium import webdriverfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.common.action_chains import ActionChainsfrom selenium.webdriver.support.select import Selecturl='https://cnhome.aviva-cofco.com.cn:8080/web2013/customer/customer_infoSearch.jsp?catid=6748%7C6786%7C7074%7C7124%7C7131&title=&month1=&month2='url='https://cnhome.aviva-cofco.com.cn:8080/web2013/customer/customer_infoSearch.jsp?catid=6748|6786|7074|7124|7131'driver = webdriver.Chrome()driver.get(url)page=driver.page_sourcep_title=re.compile(r"""<option value=.*>(.*?)</option>""")title=p_title.findall(page)[1:]zhongying=pd.DataFrame()for k in title: url='https://cnhome.aviva-cofco.com.cn:8080/web2013/customer/customer_infoSearch.jsp?catid=6748%7C6786%7C7074%7C7124%7C7131&title='+k+'&month1=&month2=' driver.get(url) page=driver.page_source p_page_num=re.compile(r'<span>(\d+)</span>') page_num=p_page_num.findall(page) print(page_num) if len(page_num)>0: page_num=pd.Series([int(i) for i in page_num]).max() else: page_num=1 result_all=pd.DataFrame() for i in range(page_num): page=driver.page_source p_columns=re.compile(r"""<th.*>(.*?)</th>""") columns=p_columns.findall(page) p_content=re.compile(r"""<td>(.*?)</td>""") content=p_content.findall(page) result=[] result1=[] for j in range(len(content)): if j%5<4: result1.append(content[j]) if j%5==4: result1.append(content[j]) result.append(result1) result1=[] result=pd.DataFrame(result) result.columns=columns result_all=result_all.append(result) try: driver.find_element_by_link_text('下一页').click() except: pass p_name=re.compile(r"""<div style="color:#57B648.*">(.*?)</div>""") name=p_name.findall(page) result_all['产品名称']=name*len(result_all) zhongying=zhongying.append(result_all)driver.quit()zhongying.to_csv('中英.csv')
阅读全文
0 0
- 中英人寿爬虫爬取,使用selenium自动化和正则表达式
- Python爬虫实践(十一):selenium+phantomjs+正则表达式爬取文章并保存
- [python爬虫] 正则表达式使用技巧及爬取个人博客实例
- [python爬虫] 正则表达式使用技巧及爬取个人博客实例
- [python爬虫] 正则表达式使用技巧及爬取个人博客实例
- Python爬虫实例(4)-用urllib、re和正则表达式爬取网页图片
- python3 [爬虫入门实战] 爬虫之使用selenium 爬取百度招聘内容并存mongodb
- 【爬虫】python selenium 爬取数据
- Python爬虫-Selenium爬取淘宝美食
- python爬虫和正则表达式
- Python自动化(一)使用Selenium+PhantomJS爬取电影下载链接
- selenium爬虫and自动化测试
- Python3网络爬虫(九):使用Selenium爬取百度文库word文章
- JS中使用正则表达式和常用正则表达式
- [python爬虫] BeautifulSoup和Selenium对比爬取豆瓣Top250电影信息
- [Python爬虫]Scrapy配合Selenium和PhantomJS爬取动态网页
- 【爬虫】 通过关键字爬取淘宝商品列表信息 selenium 的 webdriverwait 和expected_conditions
- [python爬虫] BeautifulSoup和Selenium简单爬取知网信息测试
- 求最大公约数
- 数据库高并发解决方法
- 并发和并行的区别
- .NET 程序在 Windows XP 下调用 SHA512CryptoServiceProvider 方法报 PlatformNotSupportedException 异常
- 执行脚本 遇到 Host key verification failed
- 中英人寿爬虫爬取,使用selenium自动化和正则表达式
- Nginx和Keepalived
- 趣图:如果 NPM 是快递公司…
- bootstrap添加移动设备支持
- 工业互联网是未来互联网的王者?
- iOS app 关于 IPv6 问题被拒的应用,通过审核办法之一
- 为什么软件开发,人多事少,还会工作量大?
- Python 练习册 0-头像右上角添加数字
- CF #443 C Short Program