使用Python和JSON解析JavaScript时出错

2024-09-29 23:28:35 发布

您现在位置:Python中文网/ 问答频道 /正文

当给定包含.ics日历(例如http://miamioh.edu/emss/offices/career-services/events/index.html)的常规网页的URL时,我试图找到.ics文件的特定URL。我最初尝试使用BeautifulSoup来解析/搜索,这在其他网站上是成功的,但在这个有JavaScript的网站上却没有。然后,我尝试使用JSON查看其中一行中是否有包含“.ics”的URL,但这也不起作用(没有打印任何内容)。为什么在我尝试搜索“.ics”时没有一行包含它

编辑:正如下面的注释所指出的,html代码不包含'.ics',因此我试图找出如何获取嵌入screenshot的图像中包含'.ics'的链接

page = requests.get(url).content
soup = bs4.BeautifulSoup(page, 'lxml')

links = soup.find_all('a')

for link in links:


    if link.get('href') != None and '.ics' in link.get('href'):
        endout = link.get('href')

        if endout[:6] == 'webcal':
            endout = 'https' + endout[6:]
        print
        print 'URL: ' + endout
        print
        return endout
    break



# code for searching JavaScript using JSON

for line in urllib2.urlopen(url):

    if '.ics' in line:
        print line

Tags: inurlforgetif网站htmlline

热门问题