V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  cc7756789  ›  全部回复第 9 页 / 共 9 页
回复总数  177
1  2  3  4  5  6  7  8  9  
2015-05-26 18:58:42 +08:00
回复了 bjlbeyond 创建的主题 程序员 父母想找一份工作,求灵感
你自己做网站或app,如果他们会用电脑的话,让他们当内容编辑。
我觉得先把代码写出来,把系统数据库等优化好,才去考虑性能问题。
2015-05-26 07:54:41 +08:00
回复了 geew 创建的主题 程序员 说说你最近生活的关键词吧
学习,迷茫,迷失
2015-05-25 19:45:26 +08:00
回复了 banxi1988 创建的主题 程序员 招了个比较菜的开发,是继续培养还是放弃?
技术不好可以培养,如果没有上进心,你是得好好考虑考虑。
2015-05-24 14:30:16 +08:00
回复了 imlinhanchao 创建的主题 程序员 做了一個純屬闲得的網站,請各位大大測試
没要下雨

正确。。。
2015-05-24 11:47:42 +08:00
回复了 cc7756789 创建的主题 Python 为什么爬虫获取的文本带有格式?
额,原来是因为空格, 只需要用 s.strip()去掉空格就可以了。。。。
answers = question.all_answer()
question.save(answers, '/home/zhg/Pictures/result.txt', 'w')
但是这种似乎不太人性化啊
期望的效果是
answers.save(....)
2015-05-19 18:58:08 +08:00
回复了 cc7756789 创建的主题 Python 多线程 VS 多进程?
@WKPlus 额,确实是加锁的关系,我理解较浅,锁一般用在什么地方?
2015-05-19 14:53:35 +08:00
回复了 cc7756789 创建的主题 Python 多线程 VS 多进程?
import requests
from bs4 import BeautifulSoup
import multiprocessing

n = 0
url_list = ['http://ubuntuforums.org/forumdisplay.php?f=333', ]
for x in range(1, 50):
n += 1
raw_url = 'http://ubuntuforums.org/forumdisplay.php?f=333&page=%d' % n
url_list.append(raw_url)

def running(url, q, lock):
lock.acquire()
html = requests.get(url)
if html.status_code == 200:
html_text = html.text
soup = BeautifulSoup(html_text)
with open('/home/zhg/Pictures/cao.txt', 'a+') as f:
for link in soup.find_all('a', 'title'):
s = 'http://ubuntuforums.org/' + str(link.get('href')) + ' ' + str(link.get_text().encode('utf-8'))
f.writelines(s)
f.writelines('\n')
lock.release()

if __name__ == '__main__':
manager = multiprocessing.Manager()
p = multiprocessing.Pool(len(url_list))
q = manager.Queue()
lock = manager.Lock()
for x in url_list:
p.apply_async(running, args=(x, q, lock))
p.close()
p.join()
print "process ended"
2015-05-19 10:06:00 +08:00
回复了 cc7756789 创建的主题 Python 多线程 VS 多进程?
@lhy360121 ubuntu
2015-05-18 17:09:49 +08:00
回复了 cc7756789 创建的主题 Python 多线程的小爬虫,测试后发现有三条内容重复了 40 多次
问题找到了,就是要爬取的网站有置顶的帖子,所以置顶的记录被重复了n次
2015-05-18 15:59:13 +08:00
回复了 cc7756789 创建的主题 Python 多线程的小爬虫,测试后发现有三条内容重复了 40 多次
我想试试能不能插入高亮 额。。。。。

import requests
from bs4 import BeautifulSoup
import threading
url_num = 0
url_list = ['http://ubuntuforums.org/forumdisplay.php?f=333',]
for x in range(1, 50):
url_num += 1
raw_url = 'http://ubuntuforums.org/forumdisplay.php?f=333&page=%d' % url_num
url_list.append(raw_url)
class MyThread(threading.Thread):
def __init__(self, func, args, name=""):
threading.Thread.__init__(self)
self.func = func
self.args = args
self.name = name
def run(self):
apply(self.func, self.args)
def running(url):
# lock.acquire()
html = requests.get(url)
if html.status_code == 200:
html_text = html.text
soup = BeautifulSoup(html_text)
with open('/home/zhg/Pictures/cao.txt', 'a+') as f:
for link in soup.find_all('a', 'title'):
s = 'http://ubuntuforums.org/' + str(link.get('href')) + ' ' + str(link.get_text().encode('utf-8'))
f.writelines(s)
f.writelines('\n')
# lock.release()
if __name__ == '__main__':
thread_list = [ MyThread(running, (url, ), running.__name__) for url in url_list ]
for t in thread_list:
t.setDaemon(True)
t.start()
for i in thread_list:
i.join()
print "process ended"
with open('/home/zhg/Pictures/cao.txt', 'r') as f:
f_list = f.readlines()
set_list = set(f_list)
for x in set_list:
if f_list.count(x) > 1:
print "the <%s> has found <%d>" % (x, f_list.count(x))
2015-05-18 15:55:32 +08:00
回复了 cc7756789 创建的主题 Python multiprocessing.Queue() 和 Queue.Queue() 有区别吗?
@clino 我的理解就是Queue模块是给多线程用的,多线程之间可以共享内存,而multiprocessing自带的Queue支持多进程间的通讯 ?
url里面这样写 Index.index() 写错了 a.index()
2015-05-12 14:45:42 +08:00
回复了 cc7756789 创建的主题 Python dict.__init__(self)是什么意思
@clino 懂了,但是后面的分号有作用吗?我去掉分号也没有出现任何错误。
2015-05-12 14:15:59 +08:00
回复了 cc7756789 创建的主题 Python dict.__init__(self)是什么意思
在学习threading。。。。。。
2015-05-01 15:26:23 +08:00
回复了 tanteng 创建的主题 Python python 能实现模拟登陆 QQ 空间吗?
可以,但是得用爬虫框架。
1  2  3  4  5  6  7  8  9  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2485 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 24ms · UTC 11:07 · PVG 19:07 · LAX 04:07 · JFK 07:07
Developed with CodeLauncher
♥ Do have faith in what you're doing.