|
本帖最后由 python_chuxue 于 2019-10-26 17:40 编辑
写了个爬虫,为何一行一行可以执行,全部一下运行得不到结果?python窗口卡死,不能输入,必须重启。
大神帮帮忙,谢谢!
代码如下:
import requests
from bs4 import BeautifulSoup
headers = {
'Referer': 'https://sockboom.cn/auth/login',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132Safari/537.36',
'cookie': 'uid=34764; email=sdfsd3%40eryrte.com; key=59606d04397660c42984f9de4e96c8b94cdc257869689; ip=cc04d1dceece7f3ce48160b3c91e9948; expire_in=1572154109'
}
node_url = 'https://sockboom.cn/user/node'
#以上代码一次性粘贴到Python中,运行正常
#下一行代码,必须单独录入,运行也正常,我估计问题就出现在这里,就是请求网页这里
resp = requests.get(node_url,headers=headers)
#以下代码,一次性粘贴,运行正常
soup = BeautifulSoup(resp.content.decode('utf-8'),'lxml')
all_node = soup.find_all('div', class_='tile')
node_list = []
for each_node in all_node:
node_title = each_node.find_all('div', class_='node-header-title')
name = node_title[0].text[1:15]
all_p_tag = each_node.find_all('p')
node_list.append(name+' 流量比例: '+all_p_tag[9].text[28])
node_list2 = []
for each_node in node_list:
if '流量比例: 2' in each_node:
node_list2.append(each_node)
for x in node_list2:
print(x)
|
|