【发布时间】:2015-03-24 22:55:51
【问题描述】:
我需要关注网站上的第一个搜索结果。
我通过从 .csv 文件中输入要查找的名称来打开网站,以便它打开已执行搜索的网站。
def name_to_url(name):
words = name.split(" ")
url = "http://website/search/results?Name="
end_of_url = "&Type=0&IncludeNlsp=True"
for word in words:
url += "%s+" % word
url += "%s" % end_of_url
return url
with open('file.csv', 'rb') as f:
reader = csv.reader(f)
for row in reader:
open_page(name_to_url(row[0]))
我知道这可能不是最漂亮或最好的方法,但现在已经足够了。我主要关心的是如何跟踪搜索返回的链接。
假设名称为“Google”,搜索返回一个带有粗体绿色文本的链接,其内容为“Google”。我看过 mechanize 但我不知道怎么做,主要是因为网站上的示例使用了正则表达式
【问题讨论】: