我正在尝试使用phantomjs抓取一个包含javascript的网页。我找到了一个按钮元素,当我点击它时,它会显示渲染下一个链接。但我没有得到我想要的确切输出。相反,我得到不同的输出,这是不需要的。
代码是:
from bs4 import BeautifulSoup
import requests
from selenium import webdriver
s = requests.session()
fg =s.get('https://in.bookmyshow.com/booktickets/INCM/32076',headers=headers)
so = BeautifulSoup(fg.text,"html.parser")
texts = so.findAll("div",{"class":"__buytickets"})
print(texts[0].a['href'])
print(fg.url)
driver = webdriver.PhantomJS()
driver.get(movie_links[0])
element = driver.find_element_by_class_name('__buytickets')
element.click()
print(driver.current_url)
我得到的输出为:
javascript:;
https://in.bookmyshow.com/booktickets/INCM/32076
https://in.bookmyshow.com/booktickets/INVB/47680
我必须得到的是:
javascript:;
https://in.bookmyshow.com/booktickets/INCM/32076
https://in.bookmyshow.com/booktickets/INCM/32076#Seatlayout
实际上,我必须获得的链接是由前一个链接的javascript生成的。如何获得此链接? (seatlayout链接)请帮忙!在此先感谢。
答案 0 :(得分:0)
使用无头Chrome或Firefox。