In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
In most cases, when we want to get a certain attribute value of a tag in the html code, such as the page source code, it is impossible to bother to use a third-party framework. In this case, we can use simple regular expressions to extract the data we want.
For example, I want the next series, most websites provide us with a lot of lists, we need to click one by one, this is very troublesome, now, we just need to use http to get the html string of the page, and then use regular expressions to get the value of the href attribute of the a tag in batches.
Now let's take the downloading of a certain movie website as an example. Now the demo is as follows:
Tool method httpSendGet:
Public static String httpSendGet (String url, String param,String charsetName) {String result = "; BufferedReader in = null; try {String urlNameString = url +"? "+ param; URL realUrl = new URL (urlNameString); / / Open the connection to URL URLConnection connection = realUrl.openConnection () / / set general request properties connection.setRequestProperty ("accept", "* / *"); connection.setRequestProperty ("connection", "Keep-Alive"); connection.setRequestProperty ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1 Sv1)") / / establish the actual connection connection.connect (); / / define the BufferedReader input stream to read the URL response in = new BufferedReader (new InputStreamReader (connection.getInputStream (), charsetName)); String line; while ((line = in.readLine ())! = null) {result + = line }} catch (Exception e) {System.out.println ("an exception occurred sending a GET request!" + e); e.printStackTrace ();} / / use the finally block to close the input stream finally {try {if (in! = null) {in.close ();}} catch (Exception e2) {e2.printStackTrace () }} return result;}
Tool method match:
Public static List match (String source, String element, String attr) {List result = new ArrayList (); String reg = "
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.