我在python 2.7中有一个脚本,它可以在这个页面中抓取表: http://www.the-numbers.com/movie/budgets/all
我想提取每个列,问题是我的代码无法识别有链接的列(第2列和第3列)。在
budgeturl = "http://www.the-numbers.com/movie/budgets/all"
s = urllib.urlopen(budgeturl).read()
htmlpage = etree.HTML(s)
htmltable = htmlpage.xpath("//td[@class='data']/text()")
在这个代码中,htmltable[0]是排名,htmltable[1]是生产预算,并从那里继续下去。 从我丢失的那些,我需要的是文本而不是链接。在
您需要修改xpath,因为并不是所有的}。
请尝试以下xpath表达式:
td
元素都有{//td//text()
。在输出:
Find string between two substrings
退货:
^{pr2}$通过http://www.convertcsv.com/html-table-to-csv.htm
您可以使用beautifulsoup执行相同操作,请参见:
beautifulSoup html csv
相关问题 更多 >
编程相关推荐