我想刮一个网站及其子页面,但这是太长了。如何优化请求或使用替代解决方案?你知道吗
下面是我正在使用的代码。仅仅加载Google主页就需要10秒。所以如果我给它280个链接,它显然是不可伸缩的
from selenium import webdriver
import time
# prepare the option for the chrome driver
options = webdriver.ChromeOptions()
options.add_argument('headless')
# start chrome browser
browser = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver" ,chrome_options=options)
start=time.time()
browser.get('http://www.google.com/xhtml')
print(time.time()-start)
browser.quit()
使用python
requests
和Beautiful soup
模块。你知道吗试着像这样使用urllib
不过,这也取决于你所拥有的连接质量
你可以用这个脚本来提高速度。多线程爬虫优于所有爬虫:
https://edmundmartin.com/multi-threaded-crawler-in-python/
之后您必须更改代码:
如果url包含“francais arabe marocain”,请将url保存在csv文件中。
之后,你可以刮在一个循环读取csv逐行相同的方式网址
相关问题 更多 >
编程相关推荐