The Python selenium chrome crawler seems to have been recognized. How else can it get around besides calling js?

here"s the thing. I was doing exercises on the food and drug safety website and found that there was such a situation on this website. As long as you use selenium to drive chrome to do any browser operation, you can"t get data

.

but after opening the website through selenium, there is no problem if you click manually.
after I also tried, I first filled in input data through selenium, and then manually clicked, but still prompted "the server did not return data".

from selenium import webdriver
import time

browser = webdriver.Chrome()
url = "http://app1.sfda.gov.cn/datasearch/face3/base.jsp?tableId=89&tableName=TABLE89&title=%CA%B3%C6%B7%CC%ED%BC%D3%BC%C1%C9%FA%B2%FA%D0%ED%BF%C9%BB%F1%D6%A4%C6%F3%D2%B5&bcId=137403916083811026153735196207"  
browser.get(url)
browser.find_element_by_id("goInt").send_keys("4")
-sharp
time.sleep(5)
browser.find_element_by_xpath("//*[@id="content"]/div/table[4]/tbody/tr/td[7]/input").click() 

I hope you can click.

Apr.01,2021

Visualization is an anti-selenium method based on js, and you can't lose any browser.find_element.
for example: you call browser.find_element_by_id ("goInt"), and all subsequent requests return a value of 400.
the following is my personal understanding:
the find_element of selenium sends a request to the local server (chromediver, parses html and js) to get the data. I have seen the source code of selenium before and opened a service locally, which can be accessed directly through the URL.

provides another solution:

from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtCore import QUrl
import time

app = QApplication([])
view = QWebEngineView()
view.load(QUrl("http://app1.sfda.gov.cn/datasearch/face3/base.jsp?tableId=89&tableName=TABLE89&title=%CA%B3%C6%B7%CC%ED%BC%D3%BC%C1%C9%FA%B2%FA%D0%ED%BF%C9%BB%F1%D6%A4%C6%F3%D2%B5&bcId=137403916083811026153735196207"))
view.show()
page = view.page()

def test():
    page.runJavaScript("document.getElementById('goInt').value = 5")
    page.runJavaScript("document.getElementById('goInt').parentNode.parentNode.childNodes[7].childNodes[0].click()")
    -sharptodo 

view.loadFinished.connect(test)
app.exec_()

Supplementary content:
Asynchronous Writing method:

from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtCore import QUrl, QThread, pyqtSignal
import time

cnt = 2
app = QApplication([])
view = QWebEngineView()
view.load(QUrl("http://app1.sfda.gov.cn/datasearch/face3/base.jsp?tableId=89&tableName=TABLE89&title=%CA%B3%C6%B7%CC%ED%BC%D3%BC%C1%C9%FA%B2%FA%D0%ED%BF%C9%BB%F1%D6%A4%C6%F3%D2%B5&bcId=137403916083811026153735196207"))
view.show()

class WorkThread(QThread):
    -sharp 
    trigger = pyqtSignal(int)
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def run(self):
        time.sleep(2)
        self.trigger.emit(cnt)


def output(_):
    global cnt
    view.page().runJavaScript('_x("//*[@id=\\"content\\"]/table[2]/tbody/tr[1]/td/p/a")[0].text', lambda r: print(r))
    if cnt < 6:
        cnt += 2
        work.trigger.disconnect()
        work.trigger.connect(next)
        work.start()

def next(id):
    view.page().runJavaScript('_x("//*[@id=\\"goInt\\"]")[0].value = %d' % id)
    time.sleep(0.5)
    view.page().runJavaScript('_x("//*[@src=\\"images/dataanniu_11.gif\\"]")[0].click()')
    work.trigger.disconnect()
    work.trigger.connect(output)
    work.start()

work = WorkThread()
work.trigger.connect(next)

def main():
    view.page().runJavaScript("""
        function _x(STR_XPATH) {
            var xresult = document.evaluate(STR_XPATH, document, null, XPathResult.ANY_TYPE, null);
            var xnodes = [];
            var xres = xresult.iterateNext();
            while (xres) {
                xnodes.push(xres);
                xres = xresult.iterateNext();
            }
            return xnodes;
        }""")
    view.page().runJavaScript('_x("//*[@id=\\"content\\"]/div/table[2]/tbody/tr[1]/td/p/a")[0].text', lambda r: print(r))
    work.start();

view.loadFinished.connect(main)
app.exec_()

result:


have you solved the problem? I'm working on this website, too.

Menu