- 帖子
- 1
- 精华
- 0
- 积分
- 5
- 阅读权限
- 10
- 注册时间
- 2018-1-22
- 最后登录
- 2018-1-22
|
import json
from urllib.parse import urlencode
import requests
from requests import RequestException
def get_page_index(keyword):
data={
'format': 'json',
'offset': 0,
'keyword': 'keyword',
'autoload': 'true',
'count': '20',
'cur_tab': 3,
'from':'gallery'
}
url = 'https://www.toutiao.com/search_content/?'+urlencode(data)
response = requests.get(url)
try:
if response.status_code == 200:
return response.text
else:
return None
except RequestException:
return None
def qwer(html):
data = json.loads(html)
try:
if data and "data" in data.keys():
for itme in data.get('data'):
yield itme.get('article_url')
except:
print('这里失败了')
def main():
html=get_page_index("红旗渠")
for url in qwer(html):
print(url)
if __name__ == '__main__':
main()
Process finished with exit code 0这条百度了下说是程序正常运行了,没什么没有url的返回啊。。。求大神帮助。。
|
|