I want to use javascript to get the data in a webpage.
In the first image, there is a highlighted link for you to click.
After that, you will get the webpage in the second image.
The desired data is highlighted.
I can get the data using requests
and BeautifulSoup
.
The data in the second image is retrieved using javascript from somewhere before displaying to us.
How to get the data using javascript?
import requests
from bs4 import BeautifulSoup
import lxml
fig1_url = r'https://huangshigongyuanzy.fang.com/'
fig2_url = r'https://huangshigongyuanzy.fang.com/house/2612049076/fangjia.htm'
headers = {'user-agent':r'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'}
resp = requests.get(fig2_url, headers=headers)
resp.encoding='GB18030'
soup = BeautifulSoup(resp.text, 'lxml')
for i in soup.find('div', {'id': 'priceListOpen'}).findAll('tr'):
for j in i.findAll('td'):
print(j.text+'|',end = ' ')
print('\n' + '-'*50)
You can run the snippet here.