These line in my script throws the error.
and also am providing you corresponding html for the same so as to analyse on description attribute which has been given in html and also it doesn't accept html id attribute with dot (.)
Macro VBA-
searchtxt.Value = "Earth"
.document.forms(0).submit
Do While .Busy
DoEvents
Loop
Do While .readyState <> 4
DoEvents
Loop
ThisWorkbook.Sheets(1).Range("A2") = "hgvgjjlj"
Set doc = .document
Set searchres = doc.getElementById("description").innerText
ThisWorkbook.Sheets(1).Range("A1").value = searchres
HTML-
<textarea onblur="this.isFocused=false;"
onkeydown="multiKeyDown(this);"
onfocus="this.isFocused=true;"
onchange="this.isFocused=false;multiModified(this)"
data-charlimit="false"
data-length="4000"
spellcheck="true"
name="u_incident_task.description"
style="width: 100%; overflow: hidden; word-wrap: break-word; resize: none; height: 356px;"
id="u_incident_task.description"
wrap="soft" specialtype="" class="form-control">Description:
Description xyz asdfghvb</textarea>
Related
I am trying to DRY up a PyQt program that calls QProgressDialog at various times. Instead of each occurrence calling a variation of this:
self.cat_progress = QProgressDialog(self.root)
self.cat_progress.setMinimumWidth(800)
self.cat_progress.setWindowTitle('Downloading Data')
self.cat_progress.setMinimumDuration(0)
self.cat_progress.setWindowModality(Qt.ApplicationModal)
self.cat_progress_label = QLabel('')
self.cat_progress.setLabel(self.cat_progress_label)
total_requests = 25
self.cat_progress.setMaximum(total_requests)
self.current_progress = 1
self.cat_progress.setValue(self.current_progress)
self.message_phase = 'Starting Collection'
self.progress_bar_max = 0
self.cat_progress_label.setText(self.message_phase)
I made a class, so that each time a progressDialog is needed I can use 3 lines, instead of 20+.
class ProgressBar(QDialog):
def __init__(self, title, label, prog_max=100):
super().__init__()
self.progress = QProgressDialog(self)
self.progress.setMinimumWidth(600)
self.progress.setWindowTitle(title)
self.progress.setMinimum(0)
self.progress.setValue(0)
self.progress.setWindowModality(Qt.WindowModal)
self.progress.setMaximum(prog_max)
self.progress.setWindowFlag(Qt.WindowContextHelpButtonHint,False) # This removes the '?' from the dialog
self.progress.setStyleSheet("""
QProgressBar {
border: 2px solid grey;
border-radius: 5px;
text-align: center
}
QProgressBar::chunk {
background-color: rgb(139, 183, 240);
width: 25px
}
QPushButton {
border: 2px solid grey;
border-radius: 5px;
padding: 5% 8%;
}
""")
self.progress_label = QLabel(label)
self.progress.setLabel(self.progress_label)
def advance_progress(self, label):
self.progress_label.setText(label)
self.progress.setValue(self.progress.value() + 1)
def canceled(self):
self.stop_progress()
def stop_progress(self):
self.deleteLater()
The issue is that one usage was relying on the built-in Cancel button's wasCanceled() boolean value. As the program runs a loop, if progress.wasCanceled(): ...start a different process. Now that progress is from a class and not directly made from QProgressDialog, I get an AttributeError: 'ProgressBar' object has no attribute 'wasCanceled'. Clicking this button will escape the dialog, but it does not progress into the next process as I need.
I've tried to add signals, connect a cancelled function, to set a userClicked boolean, etc. Some things broke the Cancel so it just resets and starts over, infinitely, when you click cancel. Some self 'clicked' the button (I had a print statement output) as the loop ran, but didn't stop the action. Once, it got to that if statement and broke out on its own.
How do I keep this as an object and also know when a user has clicked Cancel?
Small demo that now works! [the key is to inherit from the right widget and to not call a new instance of QProgressDialog]:
import sys
import time
from PyQt5.QtWidgets import QMainWindow, QApplication, QProgressDialog, QLabel, QPushButton
from PyQt5.QtCore import Qt
class ProgressBar(QProgressDialog):
def __init__(self, title, label, prog_max=100):
super().__init__()
self.setMinimumWidth(600)
self.setWindowTitle(title)
self.setMinimum(0)
self.setValue(0)
self.setWindowModality(Qt.WindowModal)
self.setMaximum(prog_max)
self.setStyleSheet("""
QProgressBar {
border: 2px solid grey;
border-radius: 5px;
text-align: center
}
QProgressBar::chunk {
background-color: rgb(139, 183, 240);
width: 25px
}
QPushButton {
border: 2px solid grey;
border-radius: 5px;
padding: 5% 8%;
}
""")
self.progress_label = QLabel(label)
self.setLabel(self.progress_label)
def advance_progress(self, label):
self.progress_label.setText(label)
self.setValue(self.value() + 1)
def canceled(self):
self.stop_progress()
def stop_progress(self):
self.deleteLater()
class Testing(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle('Testing Progress')
btn = QPushButton('Start progress bar')
btn.clicked.connect(self.run_progress)
self.setCentralWidget(btn)
def run_progress(self):
# Title, Label, setMaximum
progress = ProgressBar('Window Running Progress', 'Testing from Element', 30)
progress.advance_progress('Starting Scan ...')
i = 0
while i < 30:
print(i)
time.sleep(2)
progress.advance_progress(f'Counting {i}')
i += 1
if progress.wasCanceled():
alert('User Stopped!')
progress.stop_progress()
progress.stop_progress()
if __name__ == '__main__':
app = QApplication(sys.argv)
test = Testing()
test.show()
sys.exit(app.exec_())
wxWidget::wxWebView->Find - https://docs.wxwidgets.org/3.0/classwx_web_view.html#ad85a7aa0351b6e6a6bffd4220f9758ee
Sample Code
wxWebView *webView;
webView = wxWebView::New(this, wxID_ANY);
webView->SetPage("<html><head><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no' /><meta content='en-us' http-equiv=\"Content-Language\" /><meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" /><title>Demo App</title><style type=\"text/css\">.auto-style8 {font-family: \"Bookman Old Style\";font-weight:bold;color:#734024;}.underline{color:#ff0000;}.text {color:#230fd2;}#wrapper1 { width: 100% ; display: table;}#wrapper {width: 100% ; display: table;}#header1 {color: #E6F0F1; display: table; background-color: #0000ff;width: 100% ; text-align: center;height: 50px;font-size: 105% ; font-weight: bold;}#header2 {background-color: #B98264;display: table; width: 100% ; height: 40px;text-align: center;color: #FFFFFF; font-size: 75% ; font-weight: bold;}.auto-style13 {text-decoration: underline;}.text2{color:#000000;text-align: justify;}</style></head> <body style=\"color:#000000;background-color:#FFFFFF\"><div id=\"header2\"><p style=\"font-size: x-medium\" class=\"auto-style13\">Demo Page<br></p></div> <p class=\"auto-style8\" style=\"width: 100%;\">To Start - <br/><br/>STEP 1. Select data</p></body></html>","");
long lMatchCount = webView->Find("a",wxWEBVIEW_FIND_HIGHLIGHT_RESULT );
if(lMatchCount == wxNOT_FOUND){
wxMessageBox("Search not found");
}else{
//wxMessageBox("Search found" + lMatchCount);
wxLogMessage("Matches: %s ",std::to_string(lMatchCount));
}
Above code works correctly and returns number of occurrences of "a".
When webview->SetPage is updated again dynamically with large text ( any dummy content will do ) and if find call is called again it crashes with Segmentation fault
If SetPage is loaded with large text in 1st instance itself it crashes as well so ruled out possibility of update causing the crash.
Also tried loading large file from local file ( default.html contains above html code - replace any long string and it crashes with same result )
wxFile fFileIn("default.html", wxFile::read);
wxFileInputStream in(fFileIn);
webView->SetPage(in,"");
fFileIn.Close();
Similar issue is reported here http://trac.wxwidgets.org/ticket/15207
As per discussion on this thread http://trac.wxwidgets.org/ticket/15207.
We have workaround to this problem ( Still don't know why this is happening and what is the root cause )
Use the code mentioned in PR https://github.com/wxWidgets/wxWidgets/pull/2626.
Call Find before the setPage
wxFile fFileIn("default.html", wxFile::read);
wxFileInputStream in(fFileIn);
webView->Find("");
webView->SetPage(in,"");
fFileIn.Close();
I am getting an RSS feed that contains img tags and in my backend velocity script, I want to extract the img src.
So, the RSS feed includes at a paragraph with an img tag like this:
<p>
<img alt="" src="//path1/path2/path3/imagename.jpg?x=1499453513435" style="margin: 5px; width: 313px; height: 400px; float: left;" />
Some text goes here...
</p>
The above is an example of the description element of the RSS feed.
I am trying to extract the img src.
I have tried something like:
#set($index1 = $!content.description.indexOf("<[^>]*>"))
#set($index2 = $!content.description.indexOf("/>"))
#set($index2 = $index2 + 2)
#set($imgsrc="$!content.description.substring($index1, $index2))
Here is what I ended using to successfully extract the image path (including the image name) of the img src value:
#set($index1 = $!content.description.indexOf("src="))
#set($index1 = $index1 + 5)
#set($index2 = $!content.description.indexOf("?x="))
#set($index2 = $index2)
#set($imgsrc=$!content.description.substring($index1, $index2))
I first explored
#set($index1 = $!content.description.indexOf("src="))
#set($index1 = $index1 + 5)
#set($index2 = $!content.description.indexOf("?x="))
#set($index2 = $index2)
#set($imgsrc=$!content.description.substring($index1, $index2))
and it worked, but I changed to the alternative after considering that the image extension may not necessarily be .jpg
Hello and good afternoon, i am in development of my project long story short i need to save my html base page with UTF8 or Unicode
Dim y As String
Dim UTF8encoding() As Byte, MyEncoder As New System.Text.UTF8Encoding(TRUE)
y = (html code should be here will be under)
Dim utf8 As New UTF8Encoding()
Dim utf8EmitBOM As New UTF8Encoding(True)
Dim code As String = y
Path = "C:\Users\OWNER\Desktop\invoice.html"
Try
Dim my_write As System.IO.StreamWriter
my_write = IO.File.CreateText(path)
my_write.write(utf8EmitBOM.GetPreamble())
UTF8encoding = System.Text.Encoding.Convert(System.Text.Encoding.UTF8, System.Text.Encoding.Unicode, MyEncoder.GetBytes(y))
my_write.WriteLine(code)
my_write.Close()
Catch ex As Exception
End Try
HTML
<html>
<style>
table, th, td
{ border: 1px solid black; }
</style>
</head>
<body><center><b>
<font size=20>Family Butcher</font></br></br></br><center><b>
<font size =4>164 Battersea Bridge Road London SW11 3AW</center></font><center><b>
<font size =4>Tel: Mob:</center></font><center><b>
<font size =4>VAT No: 835522334</center></br></font></br>
<table Border = 3 WIDTH=610 align=left></br><tr>
<th colspan=3 align = left>To: " & txto & " <br/>
<br/>Date: <br/><br/>Invoice nº <br/></th></tr>
<td WIDTH = 100 HEIGHT=40><center><b>Quantity </b></td>
<td WIDTH = 400><center><b>Description</b></td><td><center>
<b>Value</b> </br></p>
</body></html>
At the moment i do not know how to save the file in either unicode or utf8 and then i cannot open the html file without the symbols "Â" Thanks for any support
I suggest you use File.WriteAllText - this overload allows you to specify encoding, so you can accomplish your goal with just one line of code, for example:
File.WriteAllText(path, code, Encoding.UTF8)
Update: I copy and pasted my example html file from here into a new file to make sure people could test with it, and then my code worked! I'm thinking this is an encoding issue because the original file was auto-generated from a Linux machine. I've tried saving a new file and reopening that one from the script, but that didn't work. I'm hoping I could still solve this using only one VBA macro by either somehow saving a new file and using the data in that one or making sure the encoding matches.
I can't seem to compare the following string correctly:
line, %
I've been trying to use the StrComp function and just using an equal sign, but both have not worked. I also used the Trim function on the strings I'm comparing to make sure there's no whitespace on either ends. I can trace through the debugger and see that the values I'm comparing are both "line, %", but the expression never evaluates to true.
Do any of the characters in this string cause me to have to do something special in order for a comparison to work?
Edit: This does work (I made a typo in my last edit):
Dim percentString As String
percentString = "line, %"
Dim test As String
test = percentString
If StrComp(percentString, test) = 0 Then
MsgBox "They are equal"
End If
However, I'm reading input from an html file, and that is not working. See below for code you can try.
Maybe it has to do with charset=ISO-8859-1 in the html input? Would the character set matter? Here is what is at the beginning: <HTML><HEAD><META CONTENT="text/html; charset=ISO-8859-1" HTTP-EQUIV="Content-Type"/>
Here is an example you can try
testFile.html
<HTML><HEAD><META CONTENT="text/html; charset=ISO-8859-1" HTTP-EQUIV="Content-Type"/><TITLE>title</TITLE><STYLE>
TABLE,TD,TH {border-style:solid; border-color:black;} TD,TH {background:white;margin:0;line-height:100%;padding-
left:0.5em;padding-right:0.5em;} TD {border-width:0 1px 0 0;} TH {border-width:1px 1px 1px 0;} TR TD.h {color:red;} TABLE
{border-spacing:0; border-collapse:collapse;border-width:0 0 1px 1px;} P,H1,H2,H3,TH {font-family:verdana,arial,sans-
serif;font-size:10pt;} TD {font-family:courier,monospace;font-size:10pt;} TABLE.hdft {border-spacing:0;border-
collapse:collapse;border-style:none;} TABLE.hdft TH,TABLE.hdft TD {border-style:none;line-height:normal;} TABLE.hdft
TH.tl,TABLE.hdft TD.tl {background:#6699CC;color:white;} TABLE.hdft TD.nv {background:#6633DD;color:white;} .nv A:link
{color:white;} .nv A:visited {color:white;} .nv A:active {color:yellow;} TABLE.hdft A:link {color:white;} TABLE.hdft
A:visited {color:white;} TABLE.hdft A:active {color:yellow;} .in {color:#356085;} TABLE.s TD {padding-left:0.25em;padding-
right:0.25em;} TABLE.s TD.l {padding-left:0.25em;padding-right:0.25em;text-align:right;background:#F0F0F0;} TABLE.s TR.z TD
{background:#FF9999;} TABLE.s TR.p TD {background:#FFFF88;} TABLE.s TR.c TD {background:#CCFFCC;} A:link
{color:#0000EE;text-decoration:none;} A:visited {color:#0000EE;text-decoration:none;} A:hover {color:#0000EE;text-
decoration:underline;} TABLE.cn {border-width:0 0 1px 0;} TABLE.s {border-width:1px 0 1px 1px;} TD.h {color:red;border-
width:0 1px 0 0;} TD.f {border-width:0 1px 0 1px;} TD.hf {color:red;border-width:0 1px 0 1px;} TH.f {border-width:1px 1px
1px 1px;} TR.cis TD {background:#F0F0F0;} TR.cis TD {border-width:1px 1px 1px 0;} TR.cis TD.h {color:red;border-width:1px
1px 1px 0;} TR.cis TD.f {border-width:1px 1px 1px 1px;} TR.cis TD.hf {color:red;border-width:1px 1px 1px 1px;} TD.b
{border-style:none;background:transparent;line-height:50%;} TD.bt {border-width:1px 0 0 0;background:transparent;line-
height:50%;} TR.o TD {background:#F0F0F0;}TABLE.it {border-style:none;}TABLE.it TD,TABLE.it TH {border-style:none;}
</STYLE></HEAD><BODY><TABLECELLSPACING="0" WIDTH="100%"><TR><TH>Report</TH></TR><TR><TD></TD></TR></TABLE><H2></H2><TABLE
CELLSPACING="0" WIDTH="100%"><TR><TH>line, %</TH></TR><TR><TD>Name</TD></TR></TABLE><H3></H3><TABLE CELLSPACING="0"
WIDTH="100%"><TR><TH>line, %</TH></TR><TR><TD>test</TD></TR></TABLE><P></P><TABLE CELLSPACING="0"
WIDTH="100%"><TR><TD></TD></TR><TR><TD></TD></TR></TABLE></BODY></HTML>
Use this VBA code and make small modifications to specify where testFile.html is.
Option Explicit
Sub percent()
Dim MyFile As String
MyFile = "testFile.html"
Dim percentString As String
percentString = CStr("line, %")
Dim ws As Worksheet
Workbooks.Open Filename:= _
"path\to\testFile" & MyFile
Dim stringVal As String
Dim val As Variant
Set ws = Worksheets("testFile")
For Each val In ws.UsedRange.Value
stringVal = CStr(val)
stringVal = Replace(stringVal, vbLf, "")
stringVal = Replace(stringVal, vbTab, "")
stringVal = Trim(Application.Clean(stringVal))
percentString = Replace(percentString, vbLf, "")
percentString = Replace(percentString, vbTab, "")
percentString = Trim(Application.Clean(percentString))
Dim res As Integer
res = StrComp(stringVal, percentString)
If res = 0 Then
MsgBox "Found the percent string"
End If
Next val
Workbooks(MyFile).Close
End Sub
It turns out there was an encoding problem. Basically, an  character showed up in the debugger only after I made a script that changed all the line, % lines into something else. Therefore, the following got rid of the  character, and this character is why I couldn't get the comparison to evaluate to true:
stringVal = Replace(stringVal, Chr(194), vbNullString)
Sorry to all of those who tried to help. Turns out this kind of question would have only been useful to try to answer if I could have uploaded the input file itself so the encoding would have stayed.
When I have run into this problem in the past I have done two things:
1) See what the string is by creating a cell that has something like:
B1= "|" & A1 & "|"
I use this on both cells to see if there is anything strange. Sometimes there are tabs or new lines that don't show up.
2) I substitute out strange things. If you find a new line you can use find replace to get rid of it all together or you can do a substitute with substr().
Hope this helps a bit. If you post the results from 1 I may be able to help more.
The StrComp function returns 0 if the strings are equal.
http://msdn.microsoft.com/pt-br/library/9s233cfc(v=vs.90).aspx
Kind regards.