[英]Python code isn't returning anything
我正在尝试在 Pycharm 中运行此代码,但是每当我尝试运行代码时,我的 shell 都没有任何输出。
import bs4
import requests
url = "https://www.indeed.com/jobs?q=python&l=Chicago%2C+IL, https://www.indeed.com/jobs?q=java&l=Chicago%2C+IL, https://www.indeed.com/jobs?q=javascript&l=Chicago%2C+IL, https://www.indeed.com/jobs?q=c%23&l=Chicago%2C+IL, https://www.indeed.com/jobs?q=php&l=Chicago%2C+IL, https://www.indeed.com/jobs?q=c%2B%2B&l=Chicago%2C+IL, https://www.indeed.com/jobs?q=sql&l=Chicago%2C+IL, https://www.indeed.com/jobs?q=ruby&l=Chicago%2C+IL, https://www.indeed.com/jobs?q=perl&l=Chicago%2C+IL, https://www.indeed.com/jobs?q=visual+basic&l=Chicago%2C+IL, https://www.indeed.com/jobs?q=.net&l=Chicago%2C+IL, https://www.indeed.com/jobs?q=python&l=Chicago%2C+IL, https://www.indeed.com/jobs?q=r&l=Chicago%2C+IL, https://www.indeed.com/jobs?q=swift&l=Chicago%2C+IL"
urls = [url]
visited = [url]
while len(urls) >0:
try:
htmltext = requests.get(urls[0])
except:
print (urls[0])
tags = bs4.BeautifulSoup(htmltext.content, 'lxml')
urls.pop(0)
for tag in tags.select('#searchCount'):
tag = (str(tag[0].getText()))
print (tag)
我不知道你到底想要什么作为你的输出。 但我试图更正你的代码
import bs4
import requests
url = //your urls
urls = url.split(","); //to make urls a list of urls and not a list that only has one element
while len(urls) > 0:
try:
htmltext = requests.get(urls[0])
except:
print (urls[0])
tags = bs4.BeautifulSoup(htmltext.content, 'lxml')
for tag in tags.select('#searchCount'):
print "inside search of " + str(urls.pop(0))
try:
tag = (str(tag.getText()))
print (tag)
except:
print "exception in search"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.