python 百度cpc点击
# coding=utf8
import urllib2
import string
import urllib
import re
import random #设置多个user_agents,防止百度限制IP
user_agents = ['Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20130406 Firefox/23.0', \
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0', \
'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533+(KHTML, like Gecko) Element Browser 5.0', \
'IBM WebExplorer /v0.94', 'Galaxy/1.0 [en] (Mac OS X 10.5.6; U; en)', \
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)', \
'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14', \
'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25', \
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36', \
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0; TheWorld)'] keywords_address="福州,厦门,深圳,广州,珠海,佛山,东莞,南昌,九江,上海,杭州,温州,宁波,石家庄,北京,保定,昆明,成都,南京,".split(',')
keywrods_category="男科医院,男科病医院,男性病医院,男子医院,包皮过长,包皮手术,包皮手术费用,勃起不好,早泄,男科,早泄手术,阳痿,早泄医院,早泄费用,前列腺,前列腺医院,前列腺肿大,不育,不孕不育".split(',') def baidu_search(keyword,pn):
p= {'wd': keyword}
req=urllib2.Request(("http://www.baidu.com/s?"+urllib.urlencode(p)+"&pn={0}&cl=3&rn=100").format(pn))
r=random.randint(0,8)
req.add_header('User-agent', user_agents[r])
req.add_header('connection','keep-alive')
res=urllib2.urlopen(req,timeout=10000)
print res.geturl()
html=res.read()
#print res.headers
res.close()
#print "%s\r\n=====html finished ======\r\n"%html
return html
def getCpc(regex,text):
arr = []
res = re.findall(regex, text)
for r in res:
if r not in arr:
arr.append(r)
return arr def geturl(keyword): html = baidu_search(keyword,1) content = unicode(html, 'utf-8','ignore')
arrList = getCpc(u"http://www.baidu.com/baidu.php\?url=[^\',^\"]*", content)
for item in arrList:
url = item
print "\r\n# math url:\r\n %s \r\n"%url
#获取标题
#title = clearTag(link[1]).encode('utf8') try:
domain=urllib2.Request(url)
r=random.randint(0,11)
domain.add_header('User-agent', user_agents[r])
domain.add_header('connection','keep-alive')
response=urllib2.urlopen(domain,timeout=10000)#time out 10s
uri=response.geturl()
response.close()
print " *target url: \r\n %s \r\n"%uri
except:
continue if __name__=='__main__':
categoryCount=len(keywrods_category)
addressCount=len(keywords_address)
for i in range(1,20):
r=random.randint(1,1000)
keyword="%s%s"%(keywords_address[r%addressCount],keywrods_category[r%categoryCount])
print "\r\n%s\r\n"%keyword
geturl(keyword)
邪恶一下,专门恶意点击竞价排名。
python 百度cpc点击的更多相关文章
- Google AdSense的CPC点击单价超百度联盟(2014)
很久没有关注AdSense了,一是访问不太方便,二是网站投放AdSense广告相当少,估计每天收入都不到1美元,所以就懒得去看了,一般都是几个月才去看一看. AdSense还行吗? AdSense点击 ...
- python--selenium简单模拟百度搜索点击器
python--selenium简单模拟百度搜索点击器 发布时间:2018-02-28 来源:网络 上传者:用户 关键字: selenium 模拟 简单 点击 搜索 百度 发表文章摘要:用途:简单模拟 ...
- python+selenium:点击页面元素时报错:WebDriverException: Message: Element is not clickable at point (1372.5, 9.5). Other element would receive the click: <li style="display: list-item;" id="tuanbox"></li>
遇到一个非常郁闷的问题,终于解决了, 问题是这样的,NN网站的价格计划,每一个价格计划需要三连击才能全部点开,第一个房型的价格计划是可以正确三连击打开的,可是第二个房弄就不行了,报错说不是可点击的 ...
- python selenium自动化点击页面链接测试
python selenium自动化点击页面链接测试 需求:现在有一个网站的页面,我希望用python自动化的测试点击这个页面上所有的在本窗口跳转,并且是本站内的链接,前往到链接页面之后在通过后退返回 ...
- [python]百度语音rest api
百度语音识别提供的api范例只有java, c, php. 如果使用Python, 需要注意: 语音文件长度是指bytes大小 可以通过len(file.read())获得 使用requests.po ...
- 完整版百度地图点击列表定位到对应位置并有交互动画效果demo
1.前言 将地图嵌入到项目中的需求很多,好吧,我一般都是用的百度地图.那么今天就主要写一个完整的demo.展示一个列表,点击列表的任一内容,在地图上定位到该位置,并有动画效果.来来来,直接上demo ...
- 百度地图点击地图显示地址详情的默认方法怎么关闭,去掉百度地图api图标信息
去掉百度地图api图标信息 调用百度地图API时,如果想去掉百度的logo,只需要在css里设置: <style> .anchorBL{display:none} </style&g ...
- python +百度语音识别+图灵对话
https://github.com/Dongvdong/python_Smartvoice 上电后,只要周围声音超过 2000,开始录音5S 录音上传百度识别,并返回结果文字输出 继续等待,周围声音 ...
- python控制selenium点击登录按钮时报错 unknown error: Element is not clickable at point
利用python控制selenium进行一个网页的登录时报错: C:\Users\Desktop\selenium\chrome>python chrome.py selenium.common ...
随机推荐
- linux下使用eclipse打开esp32工程文件,并进行编译下载。
在之前的文章中,已经讲过将esp-idf 运用linux自带的工具下载,但是为了开发的系统性,这里运用eclipse来对idf进行整体的编译. 首先 cd /esp32 运行eclipse,将work ...
- spring redis @Cacheable注解使用部分错误及无效原因
spring redis @Cacheable注解使用部分错误及无效原因 说明: spring项目用到redis注解无效,解决问题中遇到一堆BUG,各种搜索,看了许多错误解决方案一一测试,对于 ...
- bash编程-sed
sed(Stream Editor)是Linux系统下的一个文本流编辑器,它将文本文件内容逐行读取到标准输出,并将此行内容写入模式空间(pattern space),然后按照给定的地址定界和命令处理匹 ...
- 安装stress模拟linux系统资源消耗
1.安装yum源:yum install epel-release -y 2.安装stress:yum install stress -y 3.使用样例:stress -c 1 -t 60 4.测试场 ...
- document.domain实现不同域名跨域
利用document.domain 实现跨域:前提条件:这两个域名必须属于同一个基础域名!而且所用的协议,端口都要一致,否则无法利用document.domain进行跨域. 两个子域名:aaa.xxx ...
- FTPClient 中 FTPClient.changeWorkingDirectory(filePath) 代码一直返回 false
FTP文件下载需要的jar包: commons-net-2.0.jar 有时可能还需要:jakarta-oro.jar 参考:FTPClient参考文档 这里记录下我碰到的问题: 刚开始我的账号和密 ...
- setAttribute的浏览器兼容性(转)
1.element要用getElementById or ByTagName来得到, 2.setAttribute("class", vName)中class是指改变"c ...
- Dispatch Queue 内存结构
Dispatch 源代码版本是libdispatch-84.5.5  会根据这个结构来分析dispatch_queue 对应的代码实现 参考 GCD源码分析3 -- dispatch_queue篇 ...
- HoloLens开发手记 - 使用混合现实捕捉 Using mixed reality capture
HoloLens给了用户混合真实世界和数字世界的体验.混合现实捕捉(MRC)使得你可以保存这种体验到图片或者视频.这使得你可以分享你的体验给其他人,这允许他们能看到和你所看到一样的全息图像.这些视频和 ...
- C# DataGridView 在最左侧显示行号方法
代码: private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { Da ...