r中正则表达式\\s|*和之间有什么区别\\s|[*]?
> gsub('\\s|*','','Aug 2013*')
[1] "Aug2013*"
> gsub('\\s|[*]','','Aug 2013*')
[1] "Aug2013"
Run Code Online (Sandbox Code Playgroud)
[ ]这里的功能是什么?
有一个页面我想在 lxml 中解析?当你点击时,表格数据会变成不同的形式。
from urllib.request import urlopen
import lxml.html
url="http://f10.eastmoney.com/f10_v2/FinanceAnalysis.aspx?code=sz300059"
material=urlopen(url).read()
root=lxml.html.parse(material)
Run Code Online (Sandbox Code Playgroud)
如果我写
set=root.xpath('//table[@id="BBMX_table"]//tr')
Run Code Online (Sandbox Code Playgroud)
我得到对应的表数据
<li class="first current" onclick="ChangeRptF10AssetStatement('30005902','8','All',this,'');">
Run Code Online (Sandbox Code Playgroud)
我得到的是:
我想得到的表数据是对应的
<li class="" onclick="ChangeRptF10AssetStatement('30005902','8','Year',this,'');">
Run Code Online (Sandbox Code Playgroud)
我想得到的是:

我怎样才能root.xpath正确地写出我的 xpath 表达式?更多信息:当你点击时???,表格会变成另一个。onclick="ChangeRptF10AssetStatement('30005902','8','Year',this,'')
我试过硒:
import lxml
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument("--headless")
browser = webdriver.Chrome(options=chrome_options,executable_path='/usr/bin/chromedriver')
browser.get("http://f10.eastmoney.com/f10_v2/FinanceAnalysis.aspx?code=sz300059")
root = lxml.html.document_fromstring(browser.page_source)
mystring = lxml.etree.tostring(root, encoding = "unicode")
with open("/tmp/test.html","w") as fh:
fh.write(mystring)
Run Code Online (Sandbox Code Playgroud)
打开/tmp/test.html,里面没有数据,我怎样才能得到我的期望数据?
prettytable.PrettyTable 可以在视觉上吸引人的格式化表格中表示表格数据,并将这些表格打印到终端.
如何将表格保存为文本文件?
我在digitalocean中创建了一个droplet,我可以使用一个vps_ip.
在我的家里,连接到互联网的方式是:route + modem + adsl.
我在家里的本地电脑上建了一个wordpress.
连接到网络时的净状态如下所示.
WAN:
MAC?ommitted for privacy
IP ?public_ip PPPoE
subnet mask?255.255.255.255
gateway?153.0.68.1
DNS?114.114.114.114 223.5.5.5
LAN
MAC?ommitted for privacy
IP ?192.168.1.1
subnet mask?255.255.255.0
DHCP?active
ifconfig
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
Run Code Online (Sandbox Code Playgroud)
我的目标:让公众访问家用电脑上的wordpress网站,vps_ip digitalocean给了我.
感谢CrypticDesigns.
https://www.digitalocean.com/community/questions/how-to-map-my-local-ip-192-168-1-100-with-my-vps_ip?
我已经在CrypticDesigns的帮助下解决了这个问题.
在我的本地网络中:
在我的路由器端口端口80和私有IP 192.168.1.100到网络外部.
在公共液滴系统中:
sudo apt-get install nginx
sudo nano /etc/nginx/sites-available/default
server {
listen *:80;
server_name vps_ip;
rewrite .* http://publlic_ip$request_uri permanent;
}
sudo service nginx restart
Run Code Online (Sandbox Code Playgroud)
任何进入vpsip的人都可以浏览我的wordpress.
重要的是我的WAN上的ip地址大约每30分钟变化一次.大约30分钟后?
publicip将更改,配置文件/ etc/nginx/sites-available/default无法正常工作.
我想对这个问题进行改进.
我的意见是完成任务:
1.在我的家用电脑
命令curl ipinfo.io/ip可以获得我的公共IP.
每隔30分钟将其写入crontab.
2.发送vpsip并在/ etc/nginx/sites-available/default中更改publicip的值
,然后重新启动nginx.
如何用shell命令表达这两个步骤使进程自动化?
Lamp安装在我的本地电脑上,其操作系统是debian8.
也就是说客户端和服务器都安装在我的本地电脑上.
以下代码在我的本地电脑上保存为setcookie.php.
<?php
setcookie("user", "Alex Porter", time()+36000);
?>
<html>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
现在php setcookie.php在我的本地电脑上执行了.以下代码全部在我的本地电脑上执行.
find / -name "cookies.sqlite"
/home/debian8/.mozilla/firefox/joww2h34.default/cookies.sqlite
sqlite3 /home/debian8/.mozilla/firefox/joww2h34.default/cookies.sqlite
sqlite> .tables
moz_cookies
sqlite> PRAGMA table_info([moz_cookies]);
0|id|INTEGER|0||1
1|baseDomain|TEXT|0||0
2|appId|INTEGER|0|0|0
3|inBrowserElement|INTEGER|0|0|0
4|name|TEXT|0||0
5|value|TEXT|0||0
6|host|TEXT|0||0
7|path|TEXT|0||0
8|expiry|INTEGER|0||0
9|lastAccessed|INTEGER|0||0
10|creationTime|INTEGER|0||0
11|isSecure|INTEGER|0||0
12|isHttpOnly|INTEGER|0||0
sqlite> select * from moz_cookies where name="Alex Porter";
sqlite> select * from moz_cookies where name="user";
Run Code Online (Sandbox Code Playgroud)
为什么没有为他们两个选择信息?
在我的Firefox中设置或不设置我的cookie吗?如果在我的firefrox上设置,为什么不能在sqlite语句中选择?
在我看来,sql命令select * from moz_cookies where name="Alex Porter";会得到这样的东西
name user value Alex Porter expires 1515832198
Run Code Online (Sandbox Code Playgroud)
什么都没有显示.按照Aadil P.的说法将文件保存为/var/www/html/tmp/setcookie.php中的setcookie.php.在firefox中执行了127.0.0.1/tmp/setcookie.php.
用萤火虫打开饼干.
这里显示的是正确的结果. …
我发现我的wordpress4.7中的CJK文章不能正确地破坏行,它包含CJK和英文字符.
这是发布前的文章.
在发布之前,所有的线都正确地断开了.
现在发布后显示如下.所有线条混乱,以意想不到的方式打破了格式错误.
我试过这样修理它.
vim /var/www/html/wp/wp-content/themes/twentysixteen/style.css
.site-inner {
margin: 0 auto;
max-width: 1320px;
position: relative;
}
.site-content {
word-wrap: break-word;overflow:hidden;
word-break:break-all;white-space:pre-wrap;
}
Run Code Online (Sandbox Code Playgroud)
要重新启动apache和wordpress,根本没有效果.
我的wordpress版本是4.7,主题是二十几岁.
我用嵌入式TinyMCE构建了一个简单的网页.
HTML部分:
<form method="post" action="dump.php">
<div id="main">
<div id="container_left">
<textarea id="mytextarea"></textarea>
<input id="submit" type="submit" value="submit">
</div>
<div id="show_right"></div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
JavaScript部分.
<script src="tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector: "textarea",
height: 250,
plugins: [
"code advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste"
],
toolbar: "code insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
setup: function (editor) {
editor.on('init …Run Code Online (Sandbox Code Playgroud) 请在此处下载附件并将其另存为/tmp/target.jpg。

您可以看到0244Rjpg,i中包含以下python代码提取字符串:
from PIL import Image
import pytesseract
import cv2
filename = "/tmp/target.jpg"
image = cv2.imread(filename)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
ret, threshold = cv2.threshold(gray,55, 255, cv2.THRESH_BINARY)
print(pytesseract.image_to_string(threshold))
Run Code Online (Sandbox Code Playgroud)
我得到的是
0244K
Run Code Online (Sandbox Code Playgroud)
正确的字符串是 0244R,如何使图像具有更高的对比度,灰度,然后使用PIL和pytesseract准确地获得所有字符?这是生成图像的网页:
该网页显示有 702 条评论。
目标 youtube 示例

我写了一个函数get_total_youtube_comments(url),很多代码是从github上的项目复制过来的。
def get_total_youtube_comments(url):
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--headless")
driver = webdriver.Chrome(options=options,executable_path='/usr/bin/chromedriver')
wait = WebDriverWait(driver,60)
driver.get(url)
SCROLL_PAUSE_TIME = 2
CYCLES = 7
html = driver.find_element_by_tag_name('html')
html.send_keys(Keys.PAGE_DOWN)
html.send_keys(Keys.PAGE_DOWN)
time.sleep(SCROLL_PAUSE_TIME * 3)
for i in range(CYCLES):
html.send_keys(Keys.END)
time.sleep(SCROLL_PAUSE_TIME)
comment_elems = driver.find_elements_by_xpath('//*[@id="content-text"]') …Run Code Online (Sandbox Code Playgroud) Yahoo网站可以通过浏览器中的2081端口打开(在Firefox中为HTTP和HTTPS设置代理端口2081)。端口 2081 提供 HTTP(S) 代理。
2080端口提供SOCKS5代理服务:
url="https://query1.finance.yahoo.com/v7/finance/download/MSFT"
curl --socks5-hostname 127.0.0.1:2080 $url -o msft.txt
Run Code Online (Sandbox Code Playgroud)
我现在可以下载 Yahoo 数据,并希望通过此代理使用yfinance库。
尝试方法1:
import yfinance as yf
msft = yf.Ticker("MSFT")
msft.history(proxy="http://127.0.0.1:2081")
msft.history(proxy="https://127.0.0.1:2081")
msft.history(proxy="socks5://127.0.0.1:2080")
Run Code Online (Sandbox Code Playgroud)
它们都不起作用!它们具有相同的输出:
MSFT: No price data found, symbol may be delisted (period=1mo)
Empty DataFrame
Columns: [Open, High, Low, Close, Adj Close, Volume]
Index: []
Run Code Online (Sandbox Code Playgroud)
尝试方法2:
MSFT: No price data found, symbol may be delisted (period=1mo)
Empty DataFrame
Columns: [Open, High, Low, Close, Adj Close, Volume]
Index: []
Run Code Online (Sandbox Code Playgroud)
输出:
cd ~
export …Run Code Online (Sandbox Code Playgroud)