我正在使用WebBrowser c#抓取网站并对其进行操作,然后再显示给用户。
例如,我希望隐藏当前网站的所有按钮。
我是通过注入Javascript来这样做的,但是我认为为时已晚,因为页面已经呈现出来了,因此在隐藏所有按钮之前会出现轻微闪烁(闪烁的网站显示了所有按钮)。
(显示所有按钮->执行JavaScript STATUS_CHOICE = (
('Unassigned', 'Unassigned'),
('Assigned', 'Assigned'),
('Testing', 'Testing'),
('Tested', 'tested'),
('Fixed', 'Fixed')
)
STATUS_CHOICE_1 = (
('Bug', 'Bug'),
('Issue', 'Issue'),
('Enhancement', 'Enhancement'),
('Not an issue or bug', 'Not an issue or bug'),
('Fixed', 'Fixed')
)
Project = models.ForeignKey(Project, on_delete=models.CASCADE)
Issue_Title = models.CharField(max_length=50, blank=True, null=True)
Situation_Type = models.CharField(max_length=25, choices=STATUS_CHOICE_1)
Basic_Description = models.CharField(max_length=100)
Detailed_Description = models.TextField(default='The Description, here.')
Status = models.CharField(max_length=18, choices=STATUS_CHOICE)
Assigned_to = models.ForeignKey(User, on_delete=models.CASCADE)
Assigned_to_Mail_ID = models.EmailField(max_length=50, blank=True, null=True)
Admin_Mail_ID = models.EmailField(max_length=50, blank=True, null=True)
Reported_by = models.CharField(max_length=50, blank=True, null=True)
Reporters_Mail_ID = models.EmailField(max_length=50, blank=True, null=True)
Reported_Date = models.DateTimeField(null=True, blank=True)
Created = models.DateTimeField(auto_now_add=True, null=True, blank=True)
Updated = models.DateTimeField(auto_now=True, null=True, blank=True)
Deadline_Date = models.DateTimeField(null=True, blank=True)
Supporting_Documents_By_Reporter = models.FileField(null=True, blank=True)
Project_Managers_Comment = models.TextField(default='The Description, here.')
Supporting_Documents_by_Project_Manager = models.FileField(null=True, blank=True)
Technicians_Comment = models.TextField(default='The Description, here.')
Supporting_Documents_by_Technician = models.FileField(null=True, blank=True)
Testers_Comment = models.TextField(default='The Description, here.')
Supporting_Documents_by_Tester = models.FileField(null=True, blank=True)
注入->隐藏所有按钮)。
.ready(function(){})
上面的代码:JavaScript注入。
如何解决闪烁(当所有按钮显示一会儿,然后在jQuery执行后将它们全部隐藏起来之前)?
我尝试通过将private void browser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
string js = "$(document).ready(function() { hideButtons(); })";
script = browser1.Document.createElement("script");
script.SetAttribute("text", js);
head.AppendChild(script);
}
的{{1}}设置为无“”或将css属性设置为DocumentCompleted
来操纵DOM对象,但是仍然存在轻微的闪烁。
OuterHtml
在呈现给用户之前,有没有一种方法可以处理DOM对象?
我该打什么电话?
答案 0 :(得分:0)
我唯一能想到的是拦截导航功能,手动拉出页面,然后在浏览器窗口中呈现HTML。
private void browser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
//Cancel the request
e.Cancel = true;
using (WebClient client = new WebClient())
{
string html = client.DownloadString(e.Url.ToString());
//Find the text that you want to replace here and replace it
browser1.DocumentText = html;
}
}