[英]why it is not entering to "for loop"
page = requests.get('http://anywebsite/anysearch/')
tree = html.fromstring(page.content)
lists = tree.xpath('.//div[@class="normal-view"]')
print "lists"
for i in lists:
print "1"
title = i.xpath('.//div[@class="post-entry"/h1//a/@href]//text()')
print title,"2"
print "3"
i have given the print("list","1","2","3") statments to check whether the program is entering into the loop or not.我已经给出了 print("list","1","2","3") 语句来检查程序是否进入循环。
The output i am getting is我得到的输出是
lists
3
[Finished in 0.3s]
The following Python 2 code successfully prints the title of the film under review using the URL you provided.以下 Python 2 代码使用您提供的 URL 成功打印了正在审查的电影的标题。
from lxml import etree
parser = etree.HTMLParser()
tree = etree.parse("http://boxofficeindia.co.in/review-mirzya/", parser)
title = tree.xpath("string(//h1)")
print title
Executing this gives:执行这个给出:
> python ~/test.py
Review: Mirzya
If this is not what you are looking for, please be more specific in your question.如果这不是您要找的,请在您的问题中更具体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.