本文整理汇总了C#中CsQuery.CQ.Select方法的典型用法代码示例。如果您正苦于以下问题:C# CQ.Select方法的具体用法?C# CQ.Select怎么用?C# CQ.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsQuery.CQ
的用法示例。
在下文中一共展示了CQ.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Render
public void Render(CQ html, IYateDataContext dataContext)
{
var selector = _selector.GetValue(dataContext).ToString();
var patterns = html.Select(selector);
var patternHtml = CQ.CreateFragment(patterns.First());
dataContext.PatternContainer.Add(
_name.GetValue(dataContext).ToString(),
new YatePattern(patternHtml, AtRules, RuleSets));
html.Select(selector).Remove();
}
示例2: BuildBundleData
public void BuildBundleData(ContentFragmentPageControl contentFragmentPage, CQ parsedContent)
{
if (Configuration.OptomizeGlobalCss)
{
//Get the themes CSS files
CQ elements = parsedContent.Select(BuildSelector);
foreach (IDomObject element in elements)
{
string mediaType = element.GetAttribute("media") ?? "screen";
if (mediaType.IndexOf("screen", StringComparison.OrdinalIgnoreCase) > -1)
{
string src = element.GetAttribute("href");
if (!string.IsNullOrEmpty(src) && mediaType.IndexOf("dynamic-style.aspx", StringComparison.OrdinalIgnoreCase) < 0 && src.EndsWith(".css"))
{
IBundledFile file = _bundledFileFactory.GetBundleFile("css", src, contentFragmentPage, "");
if (file != null)
{
HandleLayoutCssPath(file);
Include(file);
}
}
}
}
}
}
示例3: Render
public void Render(CQ dom)
{
foreach (var selector in _renderingParameters.Selectors)
{
////todo: figure out prepend and such
//if (renderingParameters.Expressions.Count() > 1)
//{
// var method = renderingParameters.Expressions[1].ToLower();
// if (method == "append")
// {
// dom.Select(selector).Text(dom.Select(selector).Text() + renderingParameters.Expressions.FirstOrDefault());
// }
// else if (method == "prepend")
// {
// dom.Select(selector).Text(renderingParameters.Expressions.FirstOrDefault() + dom.Select(selector).Text());
// }
// else
// {
// dom.Select(selector).Text(renderingParameters.Expressions.FirstOrDefault());
// }
//}
//else
//{
dom.Select(selector).Text(_renderingParameters.Expressions.FirstOrDefault());
//}
}
}
示例4: Render
public void Render(CQ dom, string selector, IYateDataContext dataContext)
{
string format;
if (_format != null)
{
format = _format.GetValue(dataContext).ToString();
}
else
{
format = dom.Select(selector).Text();
}
dom.Select(selector).Text(
string.Format(format, _text.GetValue(dataContext)));
}
示例5: ParseCommandsNames
static string[] ParseCommandsNames(CQ dom, IDomObject @event)
{
var commands =
dom.Select(
"td.today-name > span.command > div.today-member-name, td.name > span.command div.member-name",
@event).Map(node => node.Cq().Text().Trim().Replace(Nbsp, ' ')).ToArray();
Debug.Assert(commands.Count() == 2, "Teams names have not been recognized: " + @event.InnerHTML);
return commands;
}
示例6: ParseEventDate
static DateTimeOffset ParseEventDate(CQ dom, IDomObject @event)
{
var date = dom.Select("td.date", @event).Text().Trim();
DateTimeOffset eventDate;
DateTimeOffset.TryParse(date, out eventDate);
return eventDate;
}
示例7: ParseEvents
static IEnumerable<ParsedEventData> ParseEvents(CQ dom, IDomObject @event)
{
return dom.Select("td.js-price", @event)
.Map(node =>
{
var domNode = node.Cq();
var coefficient = double.Parse(domNode.Find("span.selection-link").Text().Trim());
var specification = domNode.Children().Remove().End().Text().Trim();
return new ParsedEventData {Coefficient = coefficient, Specification = specification};
});
}
示例8: ParseLines
static IEnumerable<EventLine> ParseLines(CQ dom, IEnumerable<string> eventNames)
{
var events = dom.Select("table.foot-market tr.event-header");
foreach (var @event in events)
{
var commands = ParseCommandsNames(dom, @event);
var eventDate = ParseEventDate(dom, @event);
var eventsData = ParseEvents(dom, @event).ToList();
yield return
new EventLine(string.Join("-", commands), eventDate, CreateBets(eventNames, eventsData).ToArray());
}
}
示例9: HTMLEnderecoParse
public HTMLEnderecoParse(WebRequest requisicao, int cep)
{
var bytes = System.Text.Encoding.ASCII.GetBytes(string.Format("cepEntrada={0}&tipoCep=&cepTemp&metodo=buscarCep", cep));
requisicao.ContentLength = bytes.Length;
using (var os = requisicao.GetRequestStream())
{
os.Write(bytes, 0, bytes.Length);
os.Close();
}
var resposta = requisicao.GetResponse();
using (var responseStream = resposta.GetResponseStream())
using (var reader = new StreamReader(responseStream))
{
var html = reader.ReadToEnd();
_csQueryParsed = CQ.Create(html);
}
if (EhValido)
{
var htmlResp = _csQueryParsed.Select(".respostadestaque");
Endereco = new Endereco
{
Bairro = htmlResp.Eq(1).Contents().ToHtmlString().Trim()
,
Cep = htmlResp.Eq(3).Contents().ToHtmlString().Trim()
,
Cidade = htmlResp.Eq(2).Contents().ToHtmlString().Trim().Split('/')[0].Trim()
,
Estado = htmlResp.Eq(2).Contents().ToHtmlString().Trim().Split('/')[1].Trim()
,
TipoDeLogradouro = htmlResp.Eq(0).Contents().ToHtmlString().Trim().Split(' ')[0]
};
var logradouro = htmlResp.Eq(0).Contents().ToHtmlString().Trim().Split(' ');
var logradouroCompleto = string.Empty;
for (var i = 0; i < logradouro.Length; i++)
{
if (i <= 0) continue;
if (logradouro[i] == "-") break;
logradouroCompleto += logradouro[i];
logradouroCompleto += " ";
}
Endereco.Logradouro = logradouroCompleto.Trim();
}
}
示例10: GetInputFields
public static Dictionary<string, string> GetInputFields(CQ dom)
{
Dictionary<string, string> result = new Dictionary<string, string>();
foreach (var v in dom.Find("input"))
{
var value = v.Cq().Attr("value");
var key = v.Cq().Attr("name");
if (!string.IsNullOrWhiteSpace(value) && !string.IsNullOrWhiteSpace(key))
{
if (!result.ContainsKey(key))
{
result.Add(key, value);
}
else
{
result[key] = value;
}
}
}
// Get all selects
foreach (var s in dom.Select("select"))
{
var select = s.Cq();
var key = select.Attr("name");
foreach (var option in select.Children("option"))
{
var opt = option.Cq();
if (!string.IsNullOrWhiteSpace(opt.Attr("selected")))
{
if (!result.ContainsKey(key))
{
result.Add(key, opt.Val());
}
else
{
result[key] = opt.Val();
}
}
}
}
return result;
}
示例11: CheckChildren
public void CheckChildren(string parentUrl, string childSelector, string html)
{
var dom = new CQ(html);
var links = dom.Select(childSelector);
var childrenChecked = 0;
Parallel.ForEach(links, new ParallelOptions() { MaxDegreeOfParallelism = Config.MaxChildThreads }, o =>
{
childrenChecked++;
var url = o.Attributes["href"];
// ignore empty
if (String.IsNullOrWhiteSpace(url))
return;
// ignore javascript
if (url.ToLower().StartsWith("javascript:"))
return;
// jump out if url should be ignored
if (Config.IgnoreUrlsStartingWith.Any(ignore => url.StartsWith(ignore)))
return;
// check for relative url
if (!url.StartsWith("http://") &&
!url.StartsWith("https://") &&
!url.StartsWith("//"))
{
if (url.StartsWith("/"))
url = new Uri(parentUrl).GetLeftPart(UriPartial.Authority) + url;
else
url = parentUrl + url;
}
// check for protocol relative url
if (url.StartsWith("//"))
{
url = new Uri(parentUrl).GetLeftPart(UriPartial.Scheme) + url.Substring(2);
}
PerformCheck(url, null, true);
});
Console.WriteLine("Checked {0} children of {1}", childrenChecked, parentUrl);
}
示例12: ProcessDisplayElement
public void ProcessDisplayElement(CQ parsedContent)
{
CQ elements = parsedContent.Select(ReplaceSelector);
bool foundFirstScript = false;
////WE can minify the inline javascript, however this costs more than the time it saves from the bytes saved not sent over the network
foreach (IDomObject element in elements)
{
string path = element.GetAttribute("src") ?? string.Empty;
if (!path.EndsWith(BundlePath))
{
if (PartOfBundle(path))
{
foundFirstScript = UpdateJavascriptPath(foundFirstScript, element);
}
}
}
}
示例13: Sort
public string Sort()
{
if (string.IsNullOrWhiteSpace(_content))
return string.Empty;
var dom = new CQ(_content);
var root = dom.Select("Project");
foreach (var element in root.Children())
{
if (element.RequiresSort())
{
element.SortChildren();
}
}
return dom.Render();
}
示例14: Render
public void Render(CQ html, string selector, IYateDataContext dataContext)
{
var domObjects = html.Select(selector);
var pattern = dataContext.PatternContainer[_patternName.GetValue(dataContext).ToString()];
var model = _model.GetValue(dataContext);
if (model is ICollection)
{
var enumModels = model as ICollection;
foreach (var enumModel in enumModels)
{
RunPattern(dataContext, enumModel, domObjects, pattern);
}
}
else
{
RunPattern(dataContext, model, domObjects, pattern);
}
}
示例15: Process
public void Process(CQ parsedContent)
{
if (_microDataEntries != null)
{
try
{
var body = parsedContent.Select("body");
Dictionary<Guid, IContent> contentLookup = new Dictionary<Guid, IContent>();
foreach (MicroDataEntry semanticEntry in _microDataEntries)
{
Guid semanticType = semanticEntry.ContentType.GetValueOrDefault(Guid.Empty);
if (semanticType == Guid.Empty)
{
ProcessSymanticEntry(semanticEntry, body);
}
else if (WebContextualContentTypes.ContainsKey(semanticType))
{
if (!contentLookup.ContainsKey(semanticType))
{
contentLookup.Add(semanticType, WebContextualContentTypes[semanticType].GetCurrentContent(new WebContext()));
}
if (contentLookup[semanticType] != null)
{
ProcessSymanticEntry(semanticEntry, body);
}
}
}
}
catch (Exception ex)
{
new Telligent.Evolution.Components.CSException(Telligent.Evolution.Components.CSExceptionType.UnknownError, "MicroDataPlugin unkonw error", ex).Log();
}
}
}