简体   繁体   English

Python斜纹:跟踪链接并获取数据

[英]Python Twill: follow link and grab data

I finally arrived to open a page and make the request I want. 我终于到达打开页面并提出我想要的请求。

#!/usr/bin/env python
from twill.commands import *

go("http://www.website.com/")
code(200) # assert page loaded fine
showforms()
# Make a search
searchStr = '%s' % n
formvalue(1, 'q', searchStr)
submit('Factorize!')
links = showlinks()

I now see all the links listed and I would like to click on the number 11 and 12 and when I'm there grab 1 value per page. 现在,我看到列出的所有链接,我想单击数字1112 ,在那儿时每页抓取1个值。

How to use follow() and what's the command used for grabbing a value? 如何使用follow()以及用于获取值的命令是什么?

The solution was: 解决方案是:

data = urllib2.urlopen(follow(str(3)))

where '3' is is the number of the link listed by links = showlinks() 其中'3'是由links = showlinks()列出的links = showlinks()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM