需求是这样的,我需要写一个爬虫把
http://www.bjbus.com/home/fun_news_list.php?uNewsType=1&uStyle=1
上的所有list和其中的链接爬下来并每天定时查看有没有新的公告。进行简单的
response = urllib2.urlopen('http://www.bjbus.com/home/fun_news_detail.php?uNewsCode=00003475&uNewsType=1')
print html = response.read()
发现没有我想要的内容,进一步我发现我想要的东西是通过这个发来的
http://www.bjbus.com/home/ajax_news_list.php
但我单独请求这个没有任何返回,尝试了自己编写headers后无果,请大神们帮帮忙
怎么才能获得所有的公告和其对应的链接。
你要用post去请求,我使用的是request库
import requests
url = 'http://www.bjbus.com/home/ajax_news_list.php'
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'}
data = {'txtPage':1, 'txtDisplayRows':9, 'txtType':1, 'txtCode':'', 'txtContainer':'content', 'txtStyle':1}
response = requests.post(url, headers = headers, data = data)
print(response.content.decode('utf-8'))
这是异步加载的,需要带上参数用post方式请求