selenium 内嵌窗口定位滚动

Selenium 配合 Chromedriver 爬取艺龙评价时,存在内嵌窗口,直接 JS 无法滚动,这里使用如下操作方法

if spider.name == 'elong':
	for i in range(2):
		rand = random.uniform(1, 4)
		time.sleep(rand)
		drag = self.driver.find_element_by_xpath("//li[@class='s_bdt'][last()-1]")
		self.driver.execute_script("arguments[0].scrollIntoView();", drag)
		time.sleep(2)
else:
	for i in range(2):
		rand = random.uniform(1, 4)
		time.sleep(rand)
		js = "window.scrollTo(0,document.body.scrollHeight)"
		self.driver.execute_script(js)
print('Chrome driver success...')

Scrapy 一些记录

UnicodeEncodeError: 'gbk' codec can't encode character '\xee' in position 22
print(response.text.encode('gbk', 'ignore').decode('gbk'))
https://zhidao.baidu.com/question/1302043991323187059.html

Scrapyd 部署出现错误 builtins.AttributeError: 'int' object has no attribute 'splitlines'

错误原因 twist 版本过高

Continue reading Scrapy 一些记录

jQuery 模拟手动点击链接代码

html 文件

<a href="http://www.baidu.com" id='alipaybtn'>jquery点我</a>

jQuery 代码

var goPay = '<span id="goPay"> <span>';
 
//给A标签中的文字添加一个能被jQuery捕获的元素
 
$('#alipaybtn').append(goPay);
 
//模拟点击A标签中的文字
 
$('#goPay').click();