Python 爬取汽车领域问答语料(自用)
#coding=utf-8 import time
import requests
from lxml import etree
from pymongo import MongoClient
from selenium import webdriver client = MongoClient("IP", 27017)
db = client["Automobile"]
collection = db["wenda_autohome"]
db.authenticate("","") driver = webdriver.Chrome(executable_path=r"D:\chromedriver_win32\chromedriver.exe") def splist(l, s):
return [l[i: i+s] for i in range(len(l)) if i%s==0] for i in range(36726, 40202):
# url = 'https://wenda.autohome.com.cn/topic/detail/40195'
url = 'https://wenda.autohome.com.cn/topic/detail/' + str(i) time.sleep(1)
driver.get(url)
html = driver.page_source
tree = etree.HTML(html) question = tree.xpath("//h1[@class='card-title']/text()")
answer_list = tree.xpath("//a[@class='text']/text()")
if question==[] or answer_list==[]:
continue n = 0
for j in answer_list: n += 1
answer_list[n-1] = j[41:-37]
if answer_list[n-1][-3:]!='...':
continue s = "//div[@class='card-reply-wrap'][" + str(n) + "]//a[@class='more']"
try:
driver.find_element_by_xpath(s).click() html_answer = driver.page_source
tree_answer = etree.HTML(html_answer)
answer_part = tree_answer.xpath("//div[@class='answer-content']/div/div[@class='ahe__area ahe__block ahe__text']/p/text()")
answer = ''
for item in answer_part:
answer += item answer_list[n-1] = answer
time.sleep(1)
driver.get(url)
except Exception as e:
print e
continue keywords = tree.xpath("//ul[@class='card-tag-list']/li/text()")
discription_list = tree.xpath("//div[@class='ahe__area ahe__block ahe__text']/p/text()")
discription = ''
for j in discription_list:
discription += j zancai = tree.xpath("//span[@class='js-praise-count']/text()")
zancai_list = splist(zancai, 2) dc = {}
dc['keywords'] = keywords
dc['question'] = question[0]
dc['discription'] = discription
dc['answer'] = answer_list
dc['zancai'] = zancai_list
dc['url'] = url collection.insert(dc) driver.close()
Python 爬取汽车领域问答语料(自用)的更多相关文章
- Python 爬取汽车之家口碑数据
本文仅供学习交流使用,如侵立删!联系方式见文末 汽车之家口碑数据 2021.8.3 更新 增加用户信息参数.认证车辆信息等 2021.3.24 更新 更新最新数据接口 2020.12.25 更新 添加 ...
- 使用python爬取MedSci上的期刊信息
使用python爬取medsci上的期刊信息,通过设定条件,然后获取相应的期刊的的影响因子排名,期刊名称,英文全称和影响因子.主要过程如下: 首先,通过分析网站http://www.medsci.cn ...
- 毕设之Python爬取天气数据及可视化分析
写在前面的一些P话:(https://jq.qq.com/?_wv=1027&k=RFkfeU8j) 天气预报我们每天都会关注,我们可以根据未来的天气增减衣物.安排出行,每天的气温.风速风向. ...
- Python 爬取所有51VOA网站的Learn a words文本及mp3音频
Python 爬取所有51VOA网站的Learn a words文本及mp3音频 #!/usr/bin/env python # -*- coding: utf-8 -*- #Python 爬取所有5 ...
- python爬取网站数据
开学前接了一个任务,内容是从网上爬取特定属性的数据.正好之前学了python,练练手. 编码问题 因为涉及到中文,所以必然地涉及到了编码的问题,这一次借这个机会算是彻底搞清楚了. 问题要从文字的编码讲 ...
- python爬取某个网页的图片-如百度贴吧
python爬取某个网页的图片-如百度贴吧 作者:vpoet mail:vpoet_sir@163.com 注:随意copy,不用告诉我 #coding:utf-8 import urllib imp ...
- Python:爬取乌云厂商列表,使用BeautifulSoup解析
在SSS论坛看到有人写的Python爬取乌云厂商,想练一下手,就照着重新写了一遍 原帖:http://bbs.sssie.com/thread-965-1-1.html #coding:utf- im ...
- python爬取免费优质IP归属地查询接口
python爬取免费优质IP归属地查询接口 具体不表,我今天要做的工作就是: 需要将数据库中大量ip查询出起归属地 刚开始感觉好简单啊,毕竟只需要从百度找个免费接口然后来个python脚本跑一晚上就o ...
- Python爬取豆瓣指定书籍的短评
Python爬取豆瓣指定书籍的短评 #!/usr/bin/python # coding=utf-8 import re import sys import time import random im ...
随机推荐
- Vuex ~ 初识
状态:data中的属性需要共享给其他vue组件使用的部分(即data中需要共用的属性) 1.初识vuex直接来个小demo 下面操作都是基于vue-cli,如果不了解先学习下vue-cli 利用n ...
- [BZOJ4456] [Zjoi2016]旅行者 分治+最短路
4456: [Zjoi2016]旅行者 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 777 Solved: 439[Submit][Status] ...
- ASP.NET MVC5(一)—— URL路由
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- CentOS6.5修改/etc/pam.d/sshd后root无法ssh登陆
现象:由于公司需要服务器的登陆操作进行安全加固,同事为了省事,直接把CentOS7上的/etc/pam.d/sshd替换掉CentOS6.5上的/etc/pam.d/sshd,导致root用户ssh登 ...
- Openstack 网络服务 Neutron计算节点部署 (十一)
一) Neutron计算节点部署 1.安装软件包 # yum install -y openstack-neutron-linuxbridge ebtables ipset 2.配置文件neutron ...
- Shiro过滤器的维护与匹配执行
servlet的初始化会触发核心过滤器的创建: public Object getObject() throws Exception { if (instance == null) { instanc ...
- 【Kubernetes】在K8s中创建StatefulSet
在K8s中创建StatefulSet 遇到的问题: 使用Deployment创建的Pod是无状态的,当挂在Volume之后,如果该Pod挂了,Replication Controller会再run一个 ...
- python搜索引擎(转)
用python如何实现一个站内搜索引擎? 先想想搜索引擎的工作流程: 1.网页搜集.用深度或者广度优先的方法搜索某个网站,保存下所有的网页,对于网页的维护采用定期搜集和增量搜集的方式. 2.建立索引库 ...
- BZOJ 1053 [HAOI2007]反素数ant(约数个数)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1053 [题目大意] 于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6 ...
- rmq问题:ST表
存板子.O(nlogn)预处理,O(1)查询.空间O(nlogn). int d[1000006][25]; int mn[1000006]; void rmq_init() { for(int i= ...