我正在尝试对使用R 中的networkd3 绘制的网络图进行一些调整forcenetwork。
特别是,我想将文本标签颜色更改为黑色(或白色,黑色背景)并将文本标签带到节点的前面。标准选项使得阅读文本标签变得非常困难,因为有些标签颜色太浅,而另一些则被密集的节点簇挡住了。
如果我也可以更改图例文本颜色,那就太好了,这样我就可以灵活地更改背景颜色。
一个可能的解决方案,在这篇文章中指出,在这里,是劫持一些未使用的参数。
forceNetwork(Links = MisLinks, Nodes = MisNodes,
Source = "source", Target = "target",
Value = "value", NodeID = "name",
Group = "group", opacity = 0.8,
linkDistance =
JS('function(){d3.select("body").style("background-color", "#DAE3F9");return 50;}'))
Run Code Online (Sandbox Code Playgroud)
但是,由于对 JS 一无所知,我不知道如何编写它,甚至不知道它是否可能。
我正在尝试从 kompass.com 抓取公司信息
但是,由于每个公司简介提供的详细信息数量不同,某些页面可能缺少元素。例如,并非所有公司都有关于“协会”的信息。在这种情况下,我的脚本需要很长时间来搜索这些缺失的元素。无论如何我可以加快搜索过程吗?
这是我的脚本的摘录:
import time
import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import ElementNotVisibleException
from lxml import html
def init_driver():
driver = webdriver.Firefox()
driver.wait = WebDriverWait(driver, 5)
return driver
def convert2text(webElement):
if webElement != []:
webElement = webElement[0].text.encode('utf8')
else:
webElement = ['NA']
return webElement
link='http://sg.kompass.com/c/mizkan-asia-pacific-pte-ltd/sg050477/'
driver = init_driver()
driver.get(link)
driver.implicitly_wait(10)
name = driver.find_elements_by_xpath("//*[@id='productDetailUpdateable']/div[1]/div[2]/div/h1")
name = convert2text(name)
## Problem:
associations …Run Code Online (Sandbox Code Playgroud)