博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2020.01.05
阅读量:2345 次
发布时间:2019-05-10

本文共 1567 字,大约阅读时间需要 5 分钟。

1、scrapy 将str转化为HTML用于xpath

from scrapy.selector import Selectornames = Selector(text=datas).xpath("//div[contains(@class,'jDesc')]/a/text()").extract()

2、selenium webdriver find_element_by_xpath()内容带参数方法:(和C语言输出是方法类似,与xpath不一样)

driver.find_element_by_xpath("//td[contains(text(),'%s')]" % cluster_name)

其中cluster_name是参数名称,%s是参数类型(当前为字符串,整型为%d),参数提前赋值

3、设置主键自增从1开始

truncate table ‘tablename'

4、豆瓣源   pip install -i https://pypi.doubanio.com/simple/  XXX

5、微博详情点击:

ac = self.web.find_element_by_xpath(".//div[@class = 'm-container-max']/div/div/div[%s]" % j).find_element_by_xpath(".//footer/div[2]/h4")self.web.execute_script("arguments[0].click();", ac)  # 用js执行

只能使用self.web.execute_script才能模拟点击微博

6、点击QQ登陆:

打开qq登陆后

 

self.web.page_source中没有左边的源代码,左边源代码在iframe中,需要再进入iframe中
self.web.switch_to.frame(self.web.find_element_by_xpath(".//iframe[@id = 'ptlogin_iframe']"))#进入iframe,如果不进入,则拿不到iframe中的源码 ac = self.web.find_element_by_xpath(".//span[@id = 'img_out_11943809']")#id根据QQ号决定 self.web.execute_script("arguments[0].click();", ac)  # 用js执行

7、微博爬虫未登录状态,每次只可以最多连续爬取29个网页内容

8 scrapyd 启动爬虫

  跳转到爬虫项目根目录下

     1、scrapyd

     2、scrapyd-deploy

    3、curl http://localhost:6800/schedule.json -d project=weibo -d spider=film

停止爬虫

curl  -d project=scrapy项目名称 -d job=运行ID

 

9 Python 启动其他py文件

# 加入cwd 并切换工作目录        GRANDFA = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))        os.chdir(GRANDFA+'/Data_Management') #跳转到待执行目录的父目录下        # pdb.set_trace()        # os.system('cd Data_Management')        os.system('python data_handle.py') #对数据进行处理

 

 

 

 

 

转载地址:http://nenvb.baihongyu.com/

你可能感兴趣的文章
Creating a Cascading Dropdown in ASP.net MVC 3 and jQuery (1)
查看>>
创建联动的 DropdownList in ASP.net MVC 3 and jQuery (2)
查看>>
HTTP触发Jenkins参数化构建(CORS Plugin)
查看>>
来自 Serenity 的 Java 8 的一些使用技巧
查看>>
ubuntu12.04--子进程 已安装 post-installation 脚本 返回了错误号 1
查看>>
系统--电脑开机一声长响
查看>>
系统--A disk read error occurred Press Ctrl+Alt+d...
查看>>
Some projects cannot be imported because they a...
查看>>
ubuntu-android--make: *** [out/host/linux-x86/o...
查看>>
原子变量与synchronized详细解释
查看>>
java.lang.OutOfMemoryError: PermGen space及其解决方法
查看>>
如何让ajaxfileupload.js支持IE9,IE10,并可以传递多个参数?
查看>>
highcharts扩展tooltip提示异步信息
查看>>
activiti--History 历史配置
查看>>
activiti--部署bpmn/bar文件详解
查看>>
win7使用Putty 连接debain
查看>>
debain 常用命令
查看>>
debain 安装amd显卡驱动
查看>>
Java Jacob 打印word文档
查看>>
Java Freemarker 根据模板生成Word
查看>>