Python爬虫怎么获取下一页的URL和网页内容?
用BeautifulSoup爬取了第一页的内容,但是不知道剩下的页面怎么爬。
首页链接是长这样的:
http://gdemba.gicp:82/interunit/ListMain.asp?FirstEnter=Yes&Style=0000100003&UID={A270A117-76A7-4059-AB8F-B11AC370240B}&TimeID=39116.81
通过点击一个“后翻一页”的gif图片按钮跳转到下一页:
第二页的链接是长这样的:
http://gdemba.gicp:82/interunit/ListMain.asp?Keywords=&Style=0000100003&DateLowerLimit=
2000-1-1&DateUpperLimit= 2015-9-11&DateLowerLimitModify=
2000-1-1&DateUpperLimitModify=
2015-9-11&Classification1=0&Classification2=0&Classification3=0&Classification4=0&Classification6=0&Classification7=0&Classification8=0&Class=&Department=001&CreatorName=&CreatorTypeID=&UID={A270A117-76A7-4059-AB8F-B11AC370240B}&SortField=&CustormCondition=&PageNo=2&TimeID=39453.14
这里怎么观察出URL的规律呢?
那个“后翻一页”的链接如下:
οnclick="javascript:window.location.href =
'ListMain.asp?Keywords=&Style=0000100003&DateLowerLimit=
2000-1-1&DateUpperLimit= 2015-9-11&DateLowerLimitModify=
2000-1-1&DateUpperLimitModify=
2015-9-11&Classification1=0&Classification2=0&Classification3=0&Classification4=0&Classification6=0&Classification7=0&Classification8=0&Class=&Department=001&CreatorName=&CreatorTypeID=&UID={A270A117-76A7-4059-AB8F-B11AC370240B}&SortField=&CustormCondition=&PageNo=3&TimeID=39509.16'
; ">
WIDTH="16" HEIGHT="16">
要怎么获取下一页的URL和网页内容呢?
有需要更多信息我可以补充上来。
补充代码:
import urllib
import urllib2
import cookielib
import re
import csv
import codecs
from bs4 import BeautifulSoup
cookie = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))
postdata = urllib.urlencode({
'LoginName':'02',
'Password':'dc20150820if'
})
req = urllib2.Request(
url = 'http://gdemba.gicp:82/VerifyUser.asp',
data = postdata
)
result = opener.open(req)
for item in cookie:
print 'Cookie:Name = '+item.name
print 'Cookie:Value = '+item.value
result = opener.open('http://gdemba.gicp:82/interunit/ListMain.asp?FirstEnter=Yes&Style=0000100003&UID={4C10B953-C0F3-4114-8341-81EF93DE7C55}&TimeID=49252.53')
info = result.read()
soup = BeautifulSoup(info, from_encoding="gb18030")
table = soup.find(id='Table11')
print table
client = ""
tag = ""
tel = ""
catalogue = ""
region = ""
client_type = ""
email = ""
creater = ""
department = ""
action = ""
f = open('table.csv', 'w')
csv_writer = csv.writer(f)
td = repile('td')
for row in table.find_all("tr"):
cells = row.find_all("td")
if len(cells) == 10:
client = cells[0].text
tag = cells[1].text
tel = cells[2].text
catalogue = cells[3].text
region = cells[4].text
client_type = cells[5].text
email = cells[6].text
creater = cells[7].text
department = cells[8].text
action = cells[9].text
csv_writer.writerow([x.encode('utf-8') for x in [client, tag, tel, catalogue, region, client_type, email, creater, department, action]])
f.close()
相关阅读:
Xcode: 调试的时候能不能让Xcode在遇到某些信号时不抛出?
qrsctl 删除多个文件的问题
jquery 选择器:not()的写法?
HTML5中如何给manifest 文件配置 MIME-type为text/cache-manifest?本地服务器环境wamp
注册twitter账号,提示无效手机号,怎么回事
安卓关注指定微博、关注指定微信公众号怎么做?
linux 下git 出现问题Permission denied (publickey).,在线等,急
为什么spring-web-3.2.0的jar包会出现在这个位置呢?
hashmap中存进相同的key是后进的将前面的值覆盖掉,有没办法可以取到先存进的值?
如何实现 UILable 根据text自动调整高度
JAVAEE项目部署的时候,报错,请问这个是什么什么错误?如何修改?
做移动端web开发非要html5?
BAE 中 markdown==2.2.0 一添加就发布失败
制作统计图怎么画平滑的曲线?
Android开发删除本地指定路径下的过期文件
多个python子线程中的某个异常退出,如何让主线程继续它的工作,或者记录下被耽搁的工作?
Qt发布程序出错
jquery 每click只顯示show一次?
请问master右边三个蓝色的横线是什么意思?
数组转换为json
更多推荐
python爬取换页_python,网页爬虫_Python爬虫怎么获取下一页的URL和网页内容?,python,网页爬虫,html - phpStudy...
发布评论