使用lxml/python解析论坛帖子
当我使用下面的代码时,它将一个div拆分为数组中的十五个项。问题是我想把这篇文章作为数组中的一个项目。这可能是因为使用lxml/python解析论坛帖子,python,parsing,web-scraping,lxml,lxml.html,Python,Parsing,Web Scraping,Lxml,Lxml.html,当我使用下面的代码时,它将一个div拆分为数组中的十五个项。问题是我想把这篇文章作为数组中的一个项目。这可能是因为标记,但我不知道如何解决它 from lxml import html import requests page = requests.get('http://www.city-data.com/forum/economics/2056372-minimum-wage-vs-liveable-wage.html') tree = html.fromstring(page.text
标记,但我不知道如何解决它
from lxml import html
import requests
page = requests.get('http://www.city-data.com/forum/economics/2056372-minimum-wage-vs-liveable-wage.html')
tree = html.fromstring(page.text)
details = tree.xpath('//div[contains(@id, "post_message_33583236")]/text()')
print len(details) #prints 15
使用xpath(非文本)查找元素,并使用以下方法: 印刷品:
With all the talk about raising the minimum wage, I think the real issue is that people are not getting a liveable wage anymore. This applies to many skilled people too in which their job tries to pay them $10-13hr for $20-30hr type of work.
Not everyone deserves a raise at walmart or other low paying jobs. I think everyone should atleast prove themselves for 6 months to year then start to gradually get a raise. You cant act a fool and get paid the same as people who work hard and try to move up in life. Even if walmart workers weren't making minimum wage and making $11hr, you cant really do much making 22k a year other than live in a cheap/borderline crime infested area
$11hr gets you about $1250 a month after taxes and health coverage at most jobs and ill list just the basic necessities in life
...
谢谢你的回复。我还有一个问题,当我写print len(细节)时,它会打印24个。这是为什么?@Simon这是这个节点有多少子节点。如果答案有用的话,别忘了接受。谢谢
With all the talk about raising the minimum wage, I think the real issue is that people are not getting a liveable wage anymore. This applies to many skilled people too in which their job tries to pay them $10-13hr for $20-30hr type of work.
Not everyone deserves a raise at walmart or other low paying jobs. I think everyone should atleast prove themselves for 6 months to year then start to gradually get a raise. You cant act a fool and get paid the same as people who work hard and try to move up in life. Even if walmart workers weren't making minimum wage and making $11hr, you cant really do much making 22k a year other than live in a cheap/borderline crime infested area
$11hr gets you about $1250 a month after taxes and health coverage at most jobs and ill list just the basic necessities in life
...