- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试通过此 XML URL http://www.rssmix.com/u/8287461/rss.xml 中的标题等标签名称查找元素但无法正常工作,请帮忙
它只是打印一张空白页,没有其他内容
browser.get("http://www.rssmix.com/u/8287461/rss.xml")
time.sleep(10)
title = browser.find_elements_by_tag_name('title')
description = browser.find_elements_by_tag_name('description')
link = browser.find_elements_by_tag_name('link')
for p_title, p_description, p_links in zip(title, description, link):
title_s = p_title.text
description_s = p_description.text
link_s = p_links.text
print (title_s + "\t" + description_s + "\t" + link_s + "\n")
最佳答案
根据您的问题,您想要从 XML URL 中提取标签,您可以使用:
fromstring()
方法和iter()
方法来自Python xml.etree.ElementTree — The ElementTree XML API 以及Selenium,如下所示:
代码块:
# -*- coding: UTF-8 -*-
from selenium import webdriver
import xml.etree.ElementTree as ET
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument('disable-infobars')
driver=webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get("http://www.rssmix.com/u/8287461/rss.xml")
root = ET.fromstring(driver.page_source)
print("Titles are : ")
for neighbor1 in root.iter('title'):
print(neighbor1.text)
print("Descriptions are : ")
for neighbor2 in root.iter('description'):
print(neighbor2.text)
print("Links are : ")
for neighbor3 in root.iter('link'):
print(neighbor3.text)
控制台输出:
Titles are :
RSSMix.com Mix ID 8287461
Paul Pierce and Baron Davis Say Warriors Are Top 5 Team Ever, Talk NBA Finals
ASAP Rocky and Skepta's Worlds Collide in "Praise the Lord (Da Shine)" Video
Scott Pruitt Might Just Be the Cheapest Crook of the Bunch
The Complete Off-White x Nike Price Guide
Pennsylvania Middle Schoolers Given Bulletproof Shields to Prepare for High-School
J. Prince Claims Kanye Contacted Him to Squash the Drake vs. Pusha-T Beef
Best Look at Black Levi's x Air Jordan 4s
Kendall Jenner Seen Making Out with Bella Hadid's 18-Year-Old Brother
How to Have an Ingrown Hair-Free Summer
Diane Keaton Is Renovating Yet Another Home
The Chic Way To Style Your Bed On The Floor
21 Plant-Filled Instagrams That Will Turn Your Black Thumb Green
The Summer Paint Trends We're Living For
Amazon Now Has All Your Favorite Hard-to-Find Skincare Products
The Best Place to Buy Tiny Homes? Amazon
Earn $10,000 Simply By Moving to This State
15 Bathroom Essentials Every Minimalist Deserves
Pink Sofas Are Our Favorite Living Room Eye Candy
'Chlorophyll' Comes to the Nike Air Max Speed Turf
# many more ...
Descriptions are :
This feed was created by mixing existing feeds from various sources.
"I'm a basketball historian, so when I look at this team, this team can play with any team in NBA history," Paul Pierce tells Complex News. "It's probably one of the top five teams ever."
ASAP Rocky's Skepta-assisted 'Testing' standout gets a gritty Dexter Navy-directed music video that brings together the worlds of New York City and London.
<p>He's the subject of a dozen probes. The newest scandal involves Chick-fil-A.</p>
What's the current market value of every Virgil Abloh Nike and Jordan Off-White collaboration?
8th graders at the St. Cornelius School in Chadds Ford, Pennsylvania were gifted bulletproof shields for their backpacks.
J Prince reiterates his claims that Drake was ready to "destroy" Pusha's career with a devastating diss track before Kanye West stepped in.
Levi's and Jordan Brand team up for a black-based version of their Air Jordan 4 collaboration.
Despite reports that Jenner has been dating Ben Simmons for weeks, the model was spotted cuddling and kissing 18-year-old Anwar Hadid following the CFDA awards.
It's the season of sunshine, swimsuits, and cocktails. But what about hair removal? Kind of the worst part of summer, right? Good thing we've put together your handy guide on how to treat and prevent ingrown hairs.
Peek inside the Tucson, Arizona home that Diane Keaton just bought for $1.5 million. The design-loving actress actually flips a lot of homes in her free time, and we can't wait to see what she does with this one.
Bedframes are bulky and expensive—so if you need to ditch yours in favor of something more low maintenance, we've got you covered. Here are our favorite hacks for styling your bed on the floor, whether you're leaning boho or prefer minimalism.
Discover the best, inspiring plant-filled Instagrams to follow. From plant photography to houseplants in stunning interiors and tips to keeping your green guys alive, these Instagram accounts have it all. For more plant guides, visit domino.
Discover the colors that are inspiring team Domino, and learn how to bring them into your home. From citron to the vibrant pinks, here are all the wall paints we can't get enough of this summer.
At this point, is there nothing Amazon can't do? From plants to their own furniture line to luxury skincare—and now this: a new, dermatologist-approved vertical making skincare easier to shop for than ever.
Looking to downsize? Amazon's got you covered. The retailer has a slew of tiny homes on the market—and one in particular is catching our eye. Here's how to get in on the small space living trend in a super accessible way.
Working remotely, and looking for a place to relocate to? Vermont just announced its Remote Worker Grant program, which will give out of state remote workers $10,000 to relocate. Get all the details here.
Looking to make your bathroom feel more like a spa? These are our picks for the best accessories for a design-forward bathroom. For more decor ideas and inspiration, head to Domino.
Love statement seating as much as we do? We are seeing dreamy pink couches all over the internet—and, we have to admit, we are obsessed. Take it from these eight living rooms, your home deserves a bold splash of pink every now and again.
# many more ...
Links are :
http://www.rssmix.com/
https://www.complex.com/sports/2018/06/paul-pierce-baron-davis-say-warriors-are-top-5-team-ever
https://www.complex.com/music/2018/06/asap-rocky-skepta-praise-the-lord-da-shine-video
https://www.esquire.com/news-politics/politics/a21087456/scott-pruitt-chick-fil-a-wife/
https://www.complex.com/sneakers/2018/06/virgil-abloh-off-white-nike-jordan-resale-price-guide/
https://www.complex.com/life/2018/06/pennsylvania-middle-school-bulletproof-shields-given-to-students-to-prepare-high-school
https://www.complex.com/music/2018/06/j-prince-claims-kanye-west-called-to-squash-drake-pusha-t-beef
https://www.complex.com/sneakers/2018/06/levis-air-jordan-4-iv-black-release-date-ao2571-001
https://www.complex.com/pop-culture/2018/06/kendall-jenner-seen-making-out-with-bella-hadids-18-year-old-brother
https://domino.com/how-to-treat-ingrown-hairs
https://domino.com/diane-keaton-tucson-arizona-home
https://domino.com/bed-on-floor-hacks
https://domino.com/best-plant-photography-instagram-accounts-to-follow
https://domino.com/summer-paint-trends
https://domino.com/amazon-professional-skin-care-section
https://domino.com/amazon-tiny-home-for-sale-2018
https://domino.com/vermont-remote-worker-grant-program
https://domino.com/bathroom-accessories-picks
https://domino.com/pink-couch
# many more ...
关于python - 如何使用 Selenium Python 从 XML URL 中按 tagName 提取元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50709755/
是否有内置函数(我知道我可以轻松创建一个)来创建简单的标签: MakeTag("Tag","myvalue") 会生成: myvalue 我宁愿使用比 XML 类更简单的东西,我所需要的只是一个像这样
我在尝试解析 HTML 文档时遇到了以下情况。我把内容以字符串的形式放到了下面的代码中。在此, anchor 标记内有一个 P 标记。如果使用 Jsoup 解析,它会在 #item1 附近添加额外的
if (((document.activeElement).parentNode).tagName == "div") { //do amazing things } 出于某种原因,我的某个特定
基本上我试图提取一些不同的 css 选择器的最后一个标签名称。 我已经在 javascript 中成功地实现了我正在谈论的内容,我正在寻找一种更紧凑的方式,最好只使用一个正则表达式。 这是我成功完成的
我在一些元素上运行一个循环,并尝试使用我在循环中获得的 id 访问另一组元素我尝试引用其他元素并获取它们的标签,这是我的代码。 function checkRequired(){ var i
我想创建一个函数来达到以下效果: function supportsElem(tagName) { // returns boolean } 哪里: supportsElem("div") //
我需要读取文件并查找并替换同一文件中的某些文本,而无需关闭阅读器。 建议任何简单的方法... 我正在读取文件,如下所示。我怎样才能将它写入同一个文件。 private static void read
我需要从我点击文档的任何元素中获取 $('this') 信息。 我尝试了以下代码: $('body').click(function(){ var element = this.tagName
我正在尝试从网站上提取一些数据,但由于我是网络抓取的新手,因此在标签名称、类代码和 ID 中感到困惑。我对此只有基本知识。 我想复制下面的数据,如果数据不存在,那么单元格应该留空,代码需要移入下一个值
我正在尝试根据条件切换 Backbone View 的 tagName。 我最初认为我可以设置一个默认的 tagName 为 'div'(我意识到这是默认的),然后在 View 的初始化函数中,检查条
我正在编写一个 iPhone 应用程序,它使用一点 JavaScript 代码来获取 UIWebView 上某个点的元素。 我有一点 iPhone 经验,但没有 javascript 经验,我在教程上
对于以下代码,element.tagName 未定义。 $('#page1').bind('pageinit', function(event) { $('form').validate({
Example Fiddle 。 我需要添加条件,以便我的代码支持输入(需要 1 个按钮生成整个 Json)。 我尝试过过滤: elements.tagName 但它给了我一个未定义的,我想这是因为
这个问题已经有答案了: How to fix error: The markup in the document following the root element must be well-for
原始问题 是否有一个 jQuery 方法可以检查选择类型并适本地设置值?例如,使用 .html() 或 .val()。 我已经制定了自己的方法来为我完成这项工作,但不确定这是否是执行此任务的最佳方法。
我有这个 jQuery 代码: $('*').mouseover(function() { $('#log').text($(this)[0].tagName);
我有我的html Hello @samplename This is my comment ... ... More .comment-details elements 在页面加载时,我想在 .com
我在 javascrip 中有一个小型模板系统,用户可以在其中以 $tagname$ 的形式放置标签。我可以将所有标签与模式匹配:/\$\w+\$/。 此外,我想专门匹配不完整的标签(它将以 $ 开头
.tagName 属性是否适用于直接元素?我一直在使用子元素作为起点让它工作,但我无法让它在直接元素上工作。 这是一个有效的例子: HTML This is paragraph 1. This is
我有以下 HTML 片段: Jill Martin rescues Savannah Guthrie from her guest
我是一名优秀的程序员,十分优秀!