惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Security Latest
Security Latest
T
The Exploit Database - CXSecurity.com
Jina AI
Jina AI
IT之家
IT之家
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
月光博客
月光博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
罗磊的独立博客
C
Cyber Attacks, Cyber Crime and Cyber Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
爱范儿
爱范儿
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
C
CERT Recently Published Vulnerability Notes
Microsoft Azure Blog
Microsoft Azure Blog
Hugging Face - Blog
Hugging Face - Blog
S
Schneier on Security
The Register - Security
The Register - Security
L
Lohrmann on Cybersecurity
博客园 - 聂微东
有赞技术团队
有赞技术团队
Know Your Adversary
Know Your Adversary
V2EX - 技术
V2EX - 技术
大猫的无限游戏
大猫的无限游戏
Project Zero
Project Zero
Simon Willison's Weblog
Simon Willison's Weblog
Last Week in AI
Last Week in AI
博客园 - Franky
D
Docker
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
H
Hacker News: Front Page
MongoDB | Blog
MongoDB | Blog
W
WeLiveSecurity
Vercel News
Vercel News
C
Check Point Blog
N
News | PayPal Newsroom
A
Arctic Wolf
T
Threat Research - Cisco Blogs
F
Full Disclosure
博客园 - 司徒正美
GbyAI
GbyAI
A
About on SuperTechFans
Webroot Blog
Webroot Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
I
InfoQ
Martin Fowler
Martin Fowler
Y
Y Combinator Blog
Latest news
Latest news
Help Net Security
Help Net Security

博客园 - BigRain

小学生学习汉字,汉字抓取 c# regex regextools cache 访问频率的思考 20130118SQL记录 PPT辅助工具 检查外链的方法 webService启用cookie的另一种方法 百度调价HttpWebRequest 装饰者模式 第一个android程序闪亮登场 SQL 的一些批量插入和修改 职责链模式的运用 State Pattern 程序人生 SerialPort实现modem的来电显示 利用枚举进行状态的设计 singleton模式 在软件开发中的运用 我对当前项目的一些看法 闲话闲说——关于异常
python 百度cpc点击
BigRain · 2016-06-27 · via 博客园 - BigRain
# 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)