我使用lxml
HTML刮使用LXML
這是一個職位
<article id="post-4855" class="post-4855 post type-post status-publish format-standard hentry category-uncategorized">
<header class="entry-header">
<h1 class="entry-title"><a href="http://aitplacements.com/uncategorized/cybage/" rel="bookmark">Cybage..</a></h1>
<div class="entry-meta">
<span class="byline"> Posted by <span class="author vcard"><a class="url fn n" href="http://aitplacements.com/author/tpoait/">TPO</a></span></span><span class="posted-on"> on <a href="http://aitplacements.com/uncategorized/cybage/" rel="bookmark"><time class="entry-date published updated" datetime="2017-09-13T11:02:32+00:00">September 13, 2017</time></a></span><span class="comments-link"> with <a href="http://aitplacements.com/uncategorized/cybage/#respond">0 Comment</a></span> </div><!-- .entry-meta -->
</header><!-- .entry-header -->
<div class="entry-content">
<p>cybage placement details shared <a href="http://aitplacements.com/uncategorized/cybage/" class="read-more">READ MORE</a></p>
</div><!-- .entry-content -->
的檢查元素對於每一個這樣的帖子,我想提取標題,內容數據報廢發佈和發佈時間。
例如在上面,詳細情況將在
{title : "Cybage..",
post : "cybage placement details shared"
datetime="2017-09-13T11:02:32+00:00"
}
直到現在什麼,我能夠實現: 網站需要登錄,我在這樣做,全成。
用於提取信息:
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64)
Chrome/42.0.2311.90'}
url = 'http://aitplacements.com/news/'
page = requests.get(url,headers=headers)
doc = html.fromstring(page.content)
#print doC# it prints <Element html at 0x7f59c38d2260>
raw_title = doc.xpath('//h1[@class="entry-title"]/a/@href/text()')
print raw_title
的raw_title給空值[]
?
我在做什麼錯了?
你應該採取看看[美麗的湯](https://www.crummy.com/softw是/ BeautifulSoup/BS4/DOC /)。這對你的需求很好。或者,如果你需要更先進的東西(例如蜘蛛),也可以使用scrapy。 – floatingpurr
我得到了空值,因爲我正在註銷,修復了問題 –