[英]python web scraping: onclick ajax request returns nothing with status 200
I am trying to scrape a table data from a website. 我正在尝试从网站上抓取表格数据。 The data I want is "hiding" behind an onclick event.
我想要的数据“隐藏”在一个onclick事件后面。
<a class="text" onclick="javascript:openPAOnSR_RS('some_sku', 'brandname','divId', 'some_args','OPC Page Details');cmTagAndLink('Open Link','OPC Page Details',null,null,null);">The Click</a>
After clicking, there is a post request and some of the details below. 点击后,有一个发布请求和下面的一些详细信息。
Request URL:http://www.somewebsite.com/catalog/tables.do?some_sku=sku&brandKey=brandname&divId=divId
Request Method:POST
Status Code:200 OK
Remote Address:23.xxxxxxxxxxx
Referrer Policy:no-referrer-when-downgrade
So I wrote the code as below but it did not return anything. 因此,我编写了如下代码,但未返回任何内容。
from urllib.parse import urlencode
from requests.exceptions import RequestException
import requests
def get_page_index():
string_param = {
'some_sku': 'sku',
'brandKey': 'brandname',
'divId': 'divId'
}
url = "http://www.somewebsite.com/catalog/tables.do?" + urlencode(string_param)
try:
response = requests.post(url=url, data=string_param)
if response.status_code == 200:
print(response.url, response.content)
return response.text
return None
except RequestException as e:
print(e)
I am getting no output and the status shows 200. How should I get the data "behind" on click event? 我没有输出,状态显示为200。如何在单击事件中“隐藏”数据?
urllib
will only respond you with the html
content, so you can't interfere with the JS stuff on that website, there are modules like robobrowser
, scrapy
but they only click the html
check boxes or buttons. urllib
只会用html
内容回复您,因此您不会干扰该网站上的JS东西,其中有robobrowser
, scrapy
类的模块,但它们仅单击html
复选框或按钮。
so other options with are preferable are. 因此,其他选项更可取。
1) Selenium
by using a headless browser using Phantom
. 1)通过使用
Phantom
的无头浏览器来Selenium
。
2) Using Scrapy + splash
2)使用
Scrapy + splash
can i ask that after what steps you are doing before clicking the button? 我可以问一下您执行了什么步骤之后再点击按钮吗?
are you clicking on the button after putting some info. 您放置一些信息后单击按钮吗? or you are just clicking the button as the website appears?
或者您只是在网站显示时单击按钮?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.