如何从HTML页面中提取数据? [英] How to extract data from HTML pages?
本文介绍了如何从HTML页面中提取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从网站中提取职位空缺,但很难从HTML网页中提取数据。有人告诉我使用网站的RSS源提取数据,但我没有得到我想要的网站。
你可以帮帮我吗。
I want to extract job vacancies from sites but there is difficulty in extracting data from HTML pages. Someone told me to use RSS feeds of sites to extract data, but I am not getting such sites which I want.
can you please help me out.
推荐答案
你好,
看看下面的代码:
Hello,
Take a look at below code:
import urllib
sock = urllib.urlopen("http://en.wikipedia.org/wiki/Tkinter")
htmlsrc= sock.read()
sock.close()
print htmlsrc
此代码将从网站获取数据。然而,它将打印HTML源。
您可以将其转储到文件中,然后通过逐行读取文件来处理它。
谢谢
This code will get the data from the site. However it will print the HTML source.
You can dump it into a file and then work on it by reading the file line by line.
Thanks
考虑一个网页包含以下html段,
Consider that an web page contains following html segment,
<div name="test_div">This is sample text</div>
您可以通过DOMDocument提取数据如下:
You can extract data by the DOMDocument is as following:
html = file_get_contents(
html = file_get_contents(
这篇关于如何从HTML页面中提取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文